This repository is intended to be the simplest possible Rails 6 + docker-compose demo.
It builds and runs a simple "hello" page locally.
Rails, Database and Webpacker are the 3 mandatory services to get things works.
$> docker -v
Docker version 17.12.0-ce
$> docker-compose -v
docker-compose version 1.18.0
Any upper version should work.
Run :
docker-compose build
Run :
docker-compose run --rm --no-deps web-srv rails new . --skip --database=postgresql
This will run the rails new
command on our web-srv
service defined in docker-compose.yml.
Flag explanations:
- --no-deps - Tells
docker-compose run
not to start any of the services independs_on
. - --skip - Tells rails NOT to overwrite existing files, such as README or .gitignore
- --database=postgresql - Tells Rails to default our db config to use postgres.
- --rm - Removes container after run
Open and change config/database.yml
default: &default
host: db-srv # <---- add this property
username: myuser # <---- add this property
Run :
docker-compose run --rm --no-deps web-srv rails generate controller hello say_hello
Flag explanations:
- --no-deps - Tells
docker-compose run
not to start any of the services independs_on
. - --rm - Removes container after run
docker-compose up
go to http://localhost:3000/hello/say_hello
- Open the browser console to check that CSS, JS loaded correctly and no 404 request occured.
- Check also the logs of the services in your terminal to notice that no error occured.
removes all docker containers, images, and volumes. Warning, all data will be lost.
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q) -f
docker volume prune
remove all files generated by the "rails new" command
rm -rf -v !("Dockerfile"|".dockerenv"|".gitignore"|"README.md"|"docker-compose.yml") && rm .browserslistrc && rm .ruby-version