Rails + Nginx + MySQL構成のアプリケーションをDockerを用いて構築しています。
docker-compose
を使用してビルドと起動をしたのですが、docker-compose ps
で一部のコンテナしか一覧に表示されません。
ご助言をいただけると幸いです。
bash
1% docker ps 2 3CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 43eb1b53984bb myapp_app "entrypoint.sh /bin/…" 14 seconds ago Up 13 seconds myapp_app_development 598567fd0e2e0 mysql:8.0.28 "docker-entrypoint.s…" 15 seconds ago Up 14 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp myapp_db_development 6c5f70cdda7a0 myapp_nginx "/docker-entrypoint.…" 15 seconds ago Up 14 seconds 0.0.0.0:80->80/tcp myapp_nginx_development 7 8% docker-compose ps 9 10 Name Command State Ports 11------------------------------------------------------------------------------------------ 12myapp_app_development entrypoint.sh /bin/sh -c b ... Up 13myapp_nginx_development /docker-entrypoint.sh /bin ... Up 0.0.0.0:80->80/tcp
開発環境
- macOS Monterey v12.1
- ruby 3.0.1
- Rails 6.1.4.4
- docker 20.10.12
- docker-compos 1.29.2
試したこと
- コンテナとイメージの再作成(キャッシュ不使用およびボリュームの再作成含む)
- curlで通信確認、ポート300に接続できない
bash
1% curl localhost:3000 2curl: (7) Failed to connect to localhost port 3000: Connection refused
- MySQLのコンテナには入れる。またユーザーやパスワード、Host類の設定はdatabase.ymlでの指定と合っている
心当たり
一度gitのローカルリポジトリをめちゃくちゃにしてしまってリモートで上書きをした際に.env
などのファイルが消えてしまいました。その後のコンテナ再作成で不具合が発生していますので、このあたりに原因があると思って調査していました。
関連コード
docker-compose.yml類
yml
1# docker-compose.yml 2version: '3' 3 4services: 5 nginx: 6 build: 7 context: . 8 dockerfile: ./nginx/Dockerfile 9 environment: 10 TZ: Asia/Tokyo 11 ports: 12 - 80:80 13 14 app: 15 build: 16 context: . 17 dockerfile: ./api/Dockerfile 18 args: 19 - RAILS_MASTER_KEY=${RAILS_MASTER_KEY} 20 environment: 21 TZ: Asia/Tokyo 22 23# docker-compose.development.yml 24version: '3' 25 26services: 27 nginx: 28 extends: 29 file: docker-compose.yml 30 service: nginx 31 container_name: myapp_nginx_development 32 ports: 33 - 80:80 34 volumes: 35 - ./nginx/myapp.conf:/etc/nginx/conf.d/myapp.conf 36 - ./nginx/nginx.conf:/etc/nginx/nginx.conf 37 - public-data:/var/www/myapp/public 38 - tmp-data:/var/www/myapp/tmp 39 tty: true 40 41 app: 42 extends: 43 file: docker-compose.yml 44 service: app 45 container_name: myapp_app_development 46 environment: 47 RAILS_ENV: development 48 volumes: 49 - ./api:/var/www/myapp 50 - public-data:/var/www/myapp/public 51 - tmp-data:/var/www/myapp/tmp 52 depends_on: 53 - db 54 - nginx 55 stdin_open: true 56 tty: true 57 58 db: 59 image: mysql:8.0.28 60 container_name: myapp_db_development 61 cap_add: 62 - SYS_NICE 63 volumes: 64 - ./etc/my.cnf:/etc/mysql/conf.d/my.cnf 65 - myapp_data:/var/lib/mysql 66 environment: 67 MYSQL_ROOT_HOST: '%' 68 MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} 69 command: --default-authentication-plugin=mysql_native_password 70 ports: 71 - 3306:3306 72 env_file: 73 - .env 74 tty: true 75 76volumes: 77 public-data: 78 tmp-data: 79 myapp_data: 80 external: true
database.yml
yml
1default: &default 2 adapter: mysql2 3 encoding: utf8mb4 4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 5 username: root 6 password: <%= ENV['DATABASE_PASSWORD'] %> 7 host: db 8 socket: /tmp/mysql.sock 9development: 10 <<: *default 11 database: myapp_development 12test: 13 <<: *default 14 database: myapp_test 15production: 16 <<: *default 17 database: myapp 18 username: <%= Rails.application.credentials.db[:user_name] %> 19 password: <%= Rails.application.credentials.db[:password] %> 20 host: <%= Rails.application.credentials.db[:endpoint] %> 21 port: 3306
ビルド&起動
bash
1% docker-compose -f docker-compose.development.yml build --no-cache 2 3% docker-compose -f docker-compose.development.yml up 4 5nginx_1 | 2022/08/17 09:55:46 [notice] 1#1: using the "epoll" event method 6nginx_1 | 2022/08/17 09:55:46 [notice] 1#1: nginx/1.23.1 7... 8nginx_1 | 2022/08/17 09:55:46 [notice] 1#1: start worker process 10 9db_1 | 2022-08-17 00:40:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started. 10db_1 | 2022-08-17 00:40:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 11db_1 | 2022-08-17 00:40:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started. 12db_1 | 2022-08-17 00:40:07+00:00 [Note] [Entrypoint]: Initializing database files 13db_1 | 2022-08-17T00:40:07.319247Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. 14db_1 | 2022-08-17T00:40:07.319382Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 43 15db_1 | 2022-08-17T00:40:07.327840Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 16db_1 | 2022-08-17T00:40:07.943192Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 17db_1 | 2022-08-17T00:40:09.477137Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 18db_1 | 2022-08-17 00:40:13+00:00 [Note] [Entrypoint]: Database files initialized 19db_1 | 2022-08-17 00:40:13+00:00 [Note] [Entrypoint]: Starting temporary server 20db_1 | mysqld will log errors to /var/lib/mysql/98567fd0e2e0.err 21db_1 | mysqld is running as pid 94 22db_1 | 2022-08-17 00:40:14+00:00 [Note] [Entrypoint]: Temporary server started. 23db_1 | '/var/run/mysqld/mysqld.sock' -> '/tmp/mysql.sock' 24db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. 25db_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it. 26db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. 27db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it. 28db_1 | 29db_1 | 2022-08-17 00:40:18+00:00 [Note] [Entrypoint]: Stopping temporary server 30db_1 | 2022-08-17 00:40:20+00:00 [Note] [Entrypoint]: Temporary server stopped 31db_1 | 32db_1 | 2022-08-17 00:40:20+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up. 33db_1 | 34db_1 | 2022-08-17T00:40:20.562971Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. 35db_1 | 2022-08-17T00:40:20.563033Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 1 36db_1 | 2022-08-17T00:40:20.580964Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 37db_1 | 2022-08-17T00:40:20.793756Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 38db_1 | 2022-08-17T00:40:21.033203Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 39db_1 | 2022-08-17T00:40:21.033370Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 40db_1 | 2022-08-17T00:40:21.035174Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 41db_1 | 2022-08-17T00:40:21.063323Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 42db_1 | 2022-08-17T00:40:21.063572Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server - GPL. 43app_1 | [9] Puma starting in cluster mode... 44app_1 | [9] * Puma version: 5.6.4 (ruby 3.0.1-p64) ("Birdie's Version") 45app_1 | [9] * Min threads: 5 46app_1 | [9] * Max threads: 5 47app_1 | [9] * Environment: development 48app_1 | [9] * Master PID: 9 49app_1 | [9] * Workers: 2 50app_1 | [9] * Restarts: (✔) hot (✖) phased 51app_1 | [9] * Preloading application 52app_1 | [9] * Listening on unix:///var/www/myapp/tmp/sockets/puma.sock 53app_1 | [9] ! WARNING: Detected 6 Thread(s) started in app boot: 54app_1 | [9] ! #<Thread:0x000055903da62a70@listen-run_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 sleep> - /usr/local/bundle/gems/rb-inotify-0.10.1/lib/rb-inotify/notifier.rb:317:in `select' 55app_1 | [9] ! #<Thread:0x000055903da61a08@listen-wait_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 sleep_forever> - /usr/local/lib/ruby/3.0.0/forwardable.rb:238:in `pop' 56app_1 | [9] ! #<Thread:0x000055903d9d86e0@listen-run_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 sleep> - /usr/local/bundle/gems/rb-inotify-0.10.1/lib/rb-inotify/notifier.rb:317:in `select' 57app_1 | [9] ! #<Thread:0x000055903d9d2790@listen-wait_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 sleep_forever> - /usr/local/lib/ruby/3.0.0/forwardable.rb:238:in `pop' 58app_1 | [9] ! #<Thread:0x000055903bc7fdf0@listen-run_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 run> - /usr/local/bundle/gems/listen-3.7.1/lib/listen/record/entry.rb:27:in `size' 59app_1 | [9] ! #<Thread:0x000055903bc7cad8@listen-wait_thread /usr/local/bundle/gems/listen-3.7.1/lib/listen/thread.rb:17 sleep_forever> - /usr/local/lib/ruby/3.0.0/forwardable.rb:238:in `pop' 60app_1 | [9] Use Ctrl-C to stop 61app_1 | [9] - Worker 1 (PID: 28) booted in 0.03s, phase: 0 62app_1 | [9] - Worker 0 (PID: 25) booted in 0.03s, phase: 0

下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/08/17 03:00
2022/08/17 04:03