$ docker-compose run --rm web rails db:create RAILS_ENV=development
を叩いた時に、以下のようなエラーが発生します。
エラーの内容
Starting hoge-master_db_1 ... done could not translate host name "db" to address: Name or service not known Couldn't create 'hoge_development' database. Please check your configuration. rake aborted! PG::ConnectionBad: could not translate host name "db" to address: Name or service not known /usr/local/bundle/gems/pg-1.2.2/lib/pg.rb:58:in `initialize' /usr/local/bundle/gems/pg-1.2.2/lib/pg.rb:58:in `new' /usr/local/bundle/gems/pg-1.2.2/lib/pg.rb:58:in `connect' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:889:in `new_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:912:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:873:in `acquire_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:595:in `checkout' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:439:in `connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1121:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_handling.rb:238:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_handling.rb:206:in `connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:126:in `create' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:185:in `block in create_current' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:479:in `block (2 levels) in each_current_configuration' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:476:in `each' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:476:in `block in each_current_configuration' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:475:in `each' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:475:in `each_current_configuration' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:39:in `block (2 levels) in <main>' /usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' Tasks: TOP => db:create (See full trace by running task with --trace)
database.yml
default: &default adapter: postgresql encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: postgres password: password host: db development: <<: *default database: hoge_development test: <<: *default database: hoge_test production: <<: *default adapter: postgresql encoding: unicode pool: 5
【補足情報】
docker-compose.yml
version: '3' services: db: build: context: . dockerfile: ./.docker/postgresql/Dockerfile volumes: - ./.docker/postgresql/volumes:/var/lib/postgresql/data environment: - DATABASE_USER=postgres - DATABASE_PASSWORD=password web: tty: true stdin_open: true build: context: . dockerfile: ./.docker/rails/Dockerfile command: bundle exec foreman start -f Procfile.dev ports: - "3000:3000" - "8000:8000" volumes: - .:/hoge - ./.docker/rails/volumes:/usr/local/bundle environment: - DATABASE_USER=postgres - DATABASE_PASSWORD=password - BUNDLE_APP_CONFIG="/hoge/.bundle" depends_on: - db
解決方法をご教授ください。
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー