Rails default Dockerfile

Docker has become an industry standard. It allows developers to create, deploy, and run applications inside containers. In Rails 7.1, Dockerfiles are included by default. This makes it easier than ever to deploy Rails applications using Docker.

Dockerfile, .dockerignore and bin/docker-entrypoint are all included. These files are meant for production deployments, not local development. With these files, we can use Docker out of the box, for example:

1
2
docker build -t app .
docker run --rm -it -p 3000:3000 --env RAILS_MASTER_KEY=<see config/master.key> app

For apps that aren’t deployed with Docker, call Rails new with --skip-docker.

Local development

For local development, we can use docked. With this tool we can install Rails without any system dependencies, other than Docker. We can spin up a new Rails app with just a few commands:

1
2
$ docker volume create ruby-bundle-cache
$ alias docked='docker run --rm -it -v ${PWD}:/rails -v ruby-bundle-cache:/bundle -p 3000:3000 ghcr.io/rails/cli'
1
2
3
$ docked rails new weblog
$ cd weblog
$ docked rails server