Jack Moore

Email: jack(at)jmoore53.com
Project Updates

Troubleshooting Database Issues with Docker and Rails

28 Jul 2019 » containers, docker, commandcenter

Containerizing applications has its benefits and downfalls. Troubleshooting can be trouble if you don’t know where to look. This is a quick overview of diagnosing a database container.

Database Troubleshooting

Create the database in the container by attaching to the container. docker ps and run docker exec -it ${container_name} bash and then mysql -u root -p and password, and then show databases; to list the databases and if it isn’t created, use create database webcommandcenter;. docker-compose up -d db exposes the ports.

Ensure you use the correct RAILS_ENV when deploying! Run docker-compose run website rake db:migrate RAILS_ENV=test to fix the failed database migrations. Essentially the problem is the rails app attempts to use the development environment and fails to connect to the mysql server.

Create a database in db Container

CREATE DATABASE db_name; i.e. webcommandcenter_dev for the dev environment and webcommandcenter for the prod environment.

Then run the database migration with RAILS_ENV=development rake db:migrate and it will update the database. This will also update the schema.rb.

More Database

See this SO for more on running a migration and updates.

Database rollbacks are also your friend, rake db rollback STEP=?.

© Jack Moore