docker-composeでdbの作成が以下のエラーによってできません
ググって色々試しましたがうまくいきませんでした
現在ローカルではsqlite3を使用しているのですが公式ドキュメントやyoutubeなどではmysqlやpostgresqlを使用されています。
dockerで作成する場合、コンテナ内の設定とローカルの設定を同じにする必要はありますか?
ちなみにdocker内のアプリを起動させることはできます
command
1ser@Users-MBP-70 official_document2 % docker-compose run web rake db:create 2Creating official_document2_web_run ... done 3could not connect to server: No such file or directory 4 Is the server running locally and accepting 5 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 6Couldn't create 'myapp_development' database. Please check your configuration. 7rake aborted! 8ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory 9 Is the server running locally and accepting 10 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 11/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client' 12/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client' 13/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' 14/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send' 15/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection' 16/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection' 17/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection' 18/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection' 19/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout' 20/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection' 21/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection' 22/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection' 23/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:283:in `connection' 24/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' 25/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create' 26/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:133:in `create' 27/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current' 28/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration' 29/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `each' 30/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration' 31/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each' 32/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration' 33/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `create_current' 34/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>' 35/usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>' 36 37Caused by: 38PG::ConnectionBad: could not connect to server: No such file or directory 39 Is the server running locally and accepting 40 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 41/usr/local/bundle/gems/pg-1.3.3/lib/pg/connection.rb:701:in `connect_start' 42/usr/local/bundle/gems/pg-1.3.3/lib/pg/connection.rb:701:in `new' 43/usr/local/bundle/gems/pg-1.3.3/lib/pg.rb:69:in `connect' 44/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client' 45/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' 46/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send' 47/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection' 48/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection' 49/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection' 50/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection' 51/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout' 52/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection' 53/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection' 54/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection' 55/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:283:in `connection' 56/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' 57/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create' 58/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:133:in `create' 59/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current' 60/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration' 61/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `each' 62/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration' 63/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each' 64/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration' 65/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `create_current' 66/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>' 67/usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>' 68Tasks: TOP => db:create 69(See full trace by running task with --trace) 70ERROR: 1
docker
1version: '3' 2services: 3 db: 4 image: mysql:8.0 5 command: --default-authentication-plugin=mysql_native_password 6 volumes: 7 - ./src/db/mysql_data:/var/lib/mysql 8 environment: 9 MYSQL_ROOT_PASSWORD: password 10 web: 11 build: . 12 command: bundle exec rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - ./src:/app 15 ports: 16 - "3000:3000" 17 depends_on: 18 - db