【Rails】【docker-compose】Railsサーバーが立ち上がらなかった場合の対処方法

Railsサーバーが立ち上がらなくてつまずいたのでメモ。
Docker初心者です。

##現象
`docker-compose up -d`でコンテナを起動しようとしたら何故か立ち上がらない・・・。
`docker-compose up`や`docker-compose start`を試してみたけれどlocalhost:3000で表示されず。

`docker-compose ps`（コンテナの確認）を実行してみると、どうやら「project_web_1」のステータスが`Exit 1`となっているのが原因っぽい。

```
    Name                   Command               State           Ports       
-----------------------------------------------------------------------------
project_db_1    docker-entrypoint.sh mysqld      Up       3306/tcp, 33060/tcp
project_web_1   bundle exec rails s -p 300 ...   Exit 1                      
```

`docker logs task_webserver_1`を実行すると以下のログが表示された。
※ここで`docker`を`docker-compose`にしていたので全然表示されなかった。。

```
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.4-p104), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started GET "/" for 172.21.0.1 at 2019-09-30 10:46:07 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
   (0.5ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Processing by Rails::WelcomeController#index as HTML
  Rendering /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb (5.2ms)
Completed 200 OK in 28ms (Views: 22.1ms | ActiveRecord: 0.0ms)


Started GET "/" for 172.21.0.1 at 2019-09-30 11:39:02 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
   (0.5ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Processing by Rails::WelcomeController#index as HTML
  Rendering /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb (1.6ms)
Completed 200 OK in 6ms (Views: 4.5ms | ActiveRecord: 0.0ms)


Started GET "/" for 172.21.0.1 at 2019-09-30 13:21:17 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
   (0.5ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Processing by Rails::WelcomeController#index as HTML
  Rendering /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb (1.6ms)
Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.0ms)


Started GET "/home/top/" for 172.21.0.1 at 2019-09-30 13:21:23 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#top as HTML
  Rendering home/top.html.erb within layouts/application
  Rendered home/top.html.erb within layouts/application (0.3ms)
Completed 200 OK in 2242ms (Views: 2226.3ms | ActiveRecord: 0.0ms)


Started GET "/home/top/" for 172.21.0.1 at 2019-09-30 13:21:40 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#top as HTML
  Rendering home/top.html.erb within layouts/application
  Rendered home/top.html.erb within layouts/application (0.4ms)
Completed 200 OK in 149ms (Views: 131.7ms | ActiveRecord: 0.0ms)


Started GET "/home/top/" for 172.21.0.1 at 2019-09-30 13:30:56 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
   (0.9ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Processing by HomeController#top as HTML
  Rendering home/top.html.erb within layouts/application
  Rendered home/top.html.erb within layouts/application (0.9ms)
Completed 200 OK in 124ms (Views: 108.3ms | ActiveRecord: 0.0ms)


Started GET "/home/top/" for 172.21.0.1 at 2019-09-30 13:31:00 +0000
Cannot render console from 172.21.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#top as HTML
  Rendering home/top.html.erb within layouts/application
  Rendered home/top.html.erb within layouts/application (0.4ms)
Completed 200 OK in 129ms (Views: 113.8ms | ActiveRecord: 0.0ms)


- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2019-09-30 14:23:32 +0000 ===
- Goodbye!
Exiting
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
A server is already running. Check /app/tmp/pids/server.pid.
Exiting
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
A server is already running. Check /app/tmp/pids/server.pid.
Exiting
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
A server is already running. Check /app/tmp/pids/server.pid.
Exiting
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
A server is already running. Check /app/tmp/pids/server.pid.
Exiting
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
A server is already running. Check /app/tmp/pids/server.pid.
Exiting
```
メチャクチャ長文・・・。
とりあえず`A server is already running. Check /app/tmp/pids/server.pid.`の文がやたらとあったので、調べてみた。

すると以下の方の記事に遭遇。
[【docker-compose】Railsサーバが起動しない場合の対処法 - Qiita](https://qiita.com/rutko/items/d55063c1501b36c512b9)

ほぼ一緒の現象でしたので「これだ！」と思い参考にさせていただきました。

記事どおり`tmp/pids/server.pid`を削除して`docker-compose up -d`で再度起動。
無事表示されました。

これ覚えておこう。

##参考サイト
途中で参考になった記事です。
[DockerでRuby on Railsの開発をしよう - Qiita](https://qiita.com/saitoeku3/items/b1aa2ae143624e551aea)