General use of Docker
Setup Docker
Add the following files to root of project:
- docker-compose.yml
- .env
- docker/dev/Dockerfile
Adapt the content of the files for your specific project.
Build the docker image with the command:
docker compose build
Ruby on Rails App
Bundle install gems with the command:
docker compose run <name_app_web> bundle install
Create Database:
docker compose run <name_app_web> bundle exec rake db:create
If you have error like network not found run the command:
docker network create <name_of_network>
Import the db:
- PostgreSql
psql --dbname <db_name> --host 127.0.0.1 --username postgres --port 5442 --file <db_name_backup.sql>
- MySql
mysql -u root -p --host 127.0.0.1 --port 3307 <db_name> < <db_name_backup.sql>
Start the container and the app:
docker compose up
Useful commands
Get the container ID
docker ps
Open the docker bash:
docker exec -it <container-id> bash
Run the rails console:
docker compose run --rm <name_app_web> bin/rails c
Run any rails / rake commands with:
docker compose run --rm <name_app_web> bundle exec <command>