前提・実現したいこと
docker-compose up
を実行したら、
ERROR: for coffee_passport_web_1 Cannot start service web: driver failed programming external connectivity on endpoint coffee_passport_web_1 (1081a4ddfadb3546143112895eaee53e0ffa41b4a5440bedaac35aed32d5ff1d): Bind for 0.0.0.0:3000 failed: port is already allocated ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint coffee_passport_web_1 (1081a4ddfadb3546143112895eaee53e0ffa41b4a5440bedaac35aed32d5ff1d): Bind for 0.0.0.0:3000 failed: port is already allocated ERROR: Encountered errors while bringing up the project.
が出てしまいました。
試したこと
docker ps
を入力しても
ocker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24d4cc7dfa0a mysql:5.7 "docker-entrypoint.s…" 29 seconds ago Up 28 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp coffee_passport_db_1
と3000番ポートと結びついてるコンテナはない
Dockerfile(ファイルの詳細は以下記述)のEXPOSE 3000 を 30001にしたら
Step 15/20 : RUN bundle exec rails webpacker:compile ---> Running in 888f08227851 bundler: failed to load command: rails (/usr/local/bundle/bin/rails) Bundler::GemNotFound: Could not find marcel-1.0.0 in any of the sources /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:86:in `block in materialize' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:80:in `map!' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:80:in `materialize' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:170:in `specs' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:237:in `specs_for' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:226:in `requested_specs' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:101:in `block in definition_method' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:20:in `setup' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler.rb:149:in `setup' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/setup.rb:20:in `block in <top (required)>' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/ui/shell.rb:136:in `with_level' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/ui/shell.rb:88:in `silence' /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/setup.rb:20:in `<top (required)>' ERROR: Service 'web' failed to build : The command '/bin/sh -c bundle exec rails webpacker:compile' returned a non-zero code: 1
とエラー内容が変わった。
該当のソースコード
Dockerfile
1FROM ruby:2.6.5 2 3## nodejsとyarnはwebpackをインストールする際に必要 4# yarnパッケージ管理ツールをインストール 5 6RUN curl http://deb.debian.org/debian/dists/buster/main/binary-amd64/by-hash/SHA256/935deda18d5bdc25fb1813d0ec99b6e0e32a084b203e518af0cf7dc79ee8ebda | head 7 8RUN apt-get update && apt-get install -y curl apt-transport-https wget && \ 9curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ 10echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ 11apt-get update && apt-get install -y yarn 12 13 14RUN /bin/sh -c /bin/sh -c bundle update --bundler 15RUN gem install bundler:2.1.4 16 17RUN mkdir /coffee_passport 18WORKDIR /coffee_passport 19COPY Gemfile /coffee_passport/Gemfile 20COPY Gemfile.lock /coffee_passport/Gemfile.lock 21RUN bundle update rails 22RUN bundle update 23RUN bundle install 24COPY . /coffee_passport 25 26RUN yarn install --check-files 27RUN bundle exec rails webpacker:compile 28 29# Add a script to be executed every time the container starts. 30COPY entrypoint.sh /usr/bin/ 31RUN chmod +x /usr/bin/entrypoint.sh 32ENTRYPOINT ["entrypoint.sh"] 33EXPOSE 3000 34 35# Start the main process. 36CMD ["rails", "server", "-b", "0.0.0.0"]
entrypoint.sh
#!/bin/bash set -e # Remove a potentially pre-existing server.pid for Rails. rm -f /coffee_passport/tmp/pids/server.pid # Then exec the container's main process (what's set as CMD in the Dockerfile). exec "$@"
rails sをした覚えがありますが、切ったはずですし、ターミナルも一回再起動しました。
ホスト側の3000番portを強制的に開放させるコマンドを実行すれば解決するのでしょうか?
またその、コマンドを御教授いただければ幸いです。
関係ないかもしれませんが、
https://qiita.com/naoki85/items/51a8b0f2cbf949d08b11
この記事の
bin/serverとかやったので、それが関係してるのかもしれないです、、、。
またDocker Desktop を再起動したら
[15/17] RUN bundle exec rails webpacker:compile: #19 0.716 bundler: failed to load command: rails (/usr/local/bundle/bin/rails) #19 0.716 Bundler::GemNotFound: Could not find marcel-1.0.0 in any of the sources
とエラー内容が変わりました。