DockerでDBを作成し、
ローカルでアプリケーション開発に進みたいのですが、
以下のエラーでDBが作成されません。
解決方法を、どなたかご教授頂けませんか?
$ docker-compose run web rake db:create Starting rails-community_db_1 ... done Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Couldn't create 'myapp_development' database. Please check your configuration. rake aborted! Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect' /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/connection_handling.rb:90:in `connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/mysql_database_tasks.rb:6:in `connection' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/mysql_database_tasks.rb:14:in `create' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:119:in `create' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:313:in `each' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/tasks/database_tasks.rb:138:in `create_current' /usr/local/bundle/gems/activerecord-5.2.5/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <main>' /usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>' Tasks: TOP => db:create (See full trace by running task with --trace)
回答ありがとうございます。
psを実行したところ、
docker-compose ps Name Command State Ports ----------------------------------------------------------------------- rails-community_db_1 docker-entrypoint.sh mysqld Exit 1 rails-community_web_1 entrypoint.sh bash -c rm - ... Exit 1
との表記が出ます。
docker-compose.ymlファイルの内容を追記します。
docker
1version: '3' 2services: 3 db: 4 image: mysql:5.7 5 environment: 6 MYSQL_USER: root 7 MYSQL_ROOT_PASSWORD: password 8 volumes: 9 - ./tmp/db:/var/lib/mysql/data 10 web: 11 build: . 12 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 13 volumes: 14 - .:/myapp 15 ports: 16 - "3000:3000" 17 depends_on: 18 - db