LoginSignup
1
0

More than 1 year has passed since last update.

DockerでRails(web)が立ち上がらずにExit 127と出る場合の対処法

Posted at

経緯

docker-compose run upなどでコンテナを起動させると、dbは立ち上がるが、Rails(web)のほうが立ち上がらず、docker-compose psで起動状態を確かめると Exit 127と表示されました。

結論

docker-compose.ymlファイル内の文法ミス

原因

まず、なぜExit 127という状態になるのか考えました。
最初に、dockerで終了したコンテナのログを見てみます。

xxx_db_1    docker-entrypoint.sh postgres    Up         5432/tcp
xxx_web_1   entrypoint.sh bash -c rm - ...   Exit 127 

つぎに、xxx_web_1のログを見てみます。

% docker logs xxx_web_1
bash: line 1:  bin/rails: No such file or directory

bin/rails というファイルやディレクトリがありません。

Dockerの設定ファイルでbin/railsの箇所を探します。

dokcer-compose.yml
web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && \
                      bin/rails db:create && \ 
                      bundle exec rails s -p 3000 -b '0.0.0.0'"

&&のあとにくる\これは何の意味があるのか。これが原因と思って、消して再度起動させてみました。

dokcer-compose.yml
command: bash -c "rm -f tmp/pids/server.pid &&
                      bin/rails db:create &&
                      bundle exec rails s -p 3000 -b '0.0.0.0'"
% docker-compose ps   
          Name                        Command               State           Ports         
------------------------------------------------------------------------------------------
xxx_db_1    docker-entrypoint.sh postgres    Up      5432/tcp              
xxx_web_1   entrypoint.sh bash -c rm - ...   Up      0.0.0.0:3000->3000/tcp

Rails(web)が立ち上がりました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0