A simple example of using Docker Compose for developing and deploying Ruby on Rails applications.
Read the full article on jigarius.com.
Follow the steps mentioned under existing app or new app depending on your
situation. That will ensure that the ror
directory is in order. After that,
follow these steps:
- Destroy any existing containers with conflicting names.
- Copy
.env.example
to.env
and modify (if required). - Create
config/database.yml
based on.docker/ror/example.database.yml
. - Build an image for Ruby on Rails:
docker-compose build
- Boot up the app by running:
docker-compose up
- Create databases by running:
docker-compose exec web rake db:create
Cool! Now your Rails app should be available at localhost:3000.
- Delete the contents of the
ror
directory. - Put the files of your existing Rails app in the
ror
directory.- The
Gemfile
should be atror/Gemfile
.
- The
If you want to start with a Rails app from scratch,
- Create the following files:
Gemfile
: You can base this on.docker/ror/example.Gemfile
.Gemfile.lock
: An empty file.
- Run the following command to install Rails. You can modify the params for
the
rails new
command as needed.docker-compose run --no-deps web rails new . --force --database=postgresql
- For a quick Rails install, use the
--minimal
flag.
- For a quick Rails install, use the
Here are some helpful commands.
docker-compose start
: Starts app containers.docker-compose stop
: Stops app containers.rake -T
: For some other helpful commands.
See docker compose docs for further info on Docker Compose.