#環境
MacOS Mojave 10.14.6
Ruby 2.6.4
Rails 5.2.2
mysql Ver 8.0.17 for osx10.14 on x86_64 (Homebrew)
#1.実現したいこと
rails sでサーバーを立ち上げたい
#2.問題
Mysql2::Error::ConnectionError
Unknown MySQL server host 'db' (0)
#3.terminal
terminal
1$ rails server 2=> Booting Puma 3=> Rails 5.2.2 application starting in development 4=> Run `rails server -h` for more startup options 5 6warning package.json: No license field 7warning No license field 8Puma starting in single mode... 9* Version 3.12.1 (ruby 2.6.4-p104), codename: Llamas in Pajamas 10* Min threads: 5, max threads: 5 11* Environment: development 12* Listening on tcp://localhost:3000 13Use Ctrl-C to stop 14Started GET "/" for ::1 at 2019-10-07 11:33:27 +0900 15 16Mysql2::Error::ConnectionError (Unknown MySQL server host 'db' (0)): 17 18$ docker-compose ps 19 Name Command State Ports 20-------------------------------------------------------------------------------- 21rails_test_db_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp 22rails_test_web_1 bundle exec rails s -p 300 ... Exit 1
#4.docker-compose.yml
version: '3' services: web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/app ports: - 3000:3000 depends_on: - db tty: true stdin_open: true db: image: mysql:5.7 volumes: - db-volume:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: password volumes: db-volume:
#5.database.yml
# MySQL. Versions 5.0 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.7/en/old-client.html # default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: password host: db development: <<: *default database: app_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: app_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: app_production username: app password: <%= ENV['APP_DATABASE_PASSWORD'] %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/07 10:31
退会済みユーザー
2019/10/07 10:48
2019/10/08 03:40