dockerのデータベースについて
Q&A
Closed
dockerを用いてrspecの勉強を行なっているものです。
docker-compose upまでは現状できています。
その前にrails db:create , db:migrateを実行しています。
docker-compose up -dを実行した状態で、rspecを走らせた時にエラーになりました。
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
Mysql2::Error:
Unknown MySQL server host 'db' (0)
調べた限りでは、databese.ymlとdocker-compose.ymlのhost名とサーバー名が違ったりしたらこんなエラーがでたりするみたいですが、見た感じどこが間違っているかわかりませんでした。
database: db/production.sqlite3
default: &default
adapter: mysql2
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
username: root
password: password
host: db
development:
<<: *default
database: development_database
# 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: test_database
production:
<<: *default
database: production_database
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
volumes:
- mysql_data:/var/lib/mysql
web:
build: .
ports:
- "3000:3000"
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
- bundle:/usr/local/bundle
depends_on:
- db
volumes:
bundle:
mysql_data:
解決策を見つけることができませんでした。
申し訳ないですが、回答していただけると幸いです。
よろしくお願いします。
追記
実行したコマンド
git clone https://github.com/everydayrails/everydayrails-rspec-2017.git
↓
cd everydayrails-rspec-2017
↓
docker-compose build
↓
docker-compose run web bundle install
↓
docker-compose up -d
↓
docker-compose exec web rails db:create
↓
docker-compose exec web rails db:migrate
↓
docker-compose run web bundle exec rspec
あとはここにある回答の中で実行したものばかりです。