Check that in your database.yml file. If you already have your Rails application and just wrap it with Docker, you should change (inside database.yml ):
socket: /var/run/mysqld/mysqld.sock
to
host: db
where db is the name of my db service from docker-compose.yml . And here is my docker-compose.yml :
version: '3' services: web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" links: - db db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root
You run your application on the console (in the application folder) as docker-compose up . Then WAIT 1 MINUTE (let your mysql service be fully loaded) until new logs appear in the console. Usually the last line should be like
db_1 | 2017-12-24T12: 25: 20.397174Z 0 [Note] The end of the list of the table without partitioning
Then (in a new terminal window) are applied:
docker-compose run web rake db:create
and then
docker-compose run web rake db:migrate
When finished, stop the downloaded images with
docker-compose stop
Do not use docker-compose down , but because if you do, you will delete the contents of your database.
The next time you want to resume your work, follow these steps:
docker-compose start
The rest of the stuff does what is explained here: https://docs.docker.com/compose/rails/
prograils
source share