Do not install anything inside your laptop :
docker run -ti -v $(pwd):/usr/src/app --entrypoint /bin/bash --workdir=/usr/src/app ruby:latest
Make dummy install inside a temporary container :
apt-get update && apt-get install -y nodejs npm git build-essential
npm install --global yarn
gem install rails
rails new my_app
Exit the container.
Copy/Paste Dockerfile
, .env.development
, docker-compose.yml
inside the root folder of the project (my_app
)
Then launch the database (postgres in example here). Setup what you need (mariadb?, sqlite? in docker-compose) :
docker-compose -f docker-compose.yml up --renew-anon-volumes --remove-orphans --force-recreate -d postgresql
Options :
--renew-anon-volumes Recreate anonymous volumes instead of retrieving
data from the previous containers.
--remove-orphans Remove containers for services not defined
in the Compose file.
--force-recreate Recreate containers even if their configuration
and image haven't changed.
-d, --detach Detached mode: Run containers in the background,
print new container names.
Launch the web application :
docker-compose -f docker-compose.yml up --renew-anon-volumes --remove-orphans --force-recreate --build web
Options :
--build Build images before starting containers.
Once it's launched the first time, you'll need to run migration & seeds :
docker-compose exec web bundle exec rake db:setup
docker-compose exec web bundle exec rake db:migrate
docker-compose exec web bundle exec rake db:seed
If you need to check logs of a demonized container :
docker-compose -f docker-compose.yml logs -f postgres
If you need to get a terminal inside a container :
docker-compose exec -ti web /bin/bash
You can access to the app with your browser at : localhost:3000
docker-compose -f docker-compose.yml down
docker kill $(docker ps -q)
Identify the container and manage it : docker ps -a
docker rm -f $(docker ps -a -q)