Ready to use Docker image for running Ruby on Rails applications. Based on official Ruby images.
2.4
,2
,latest
2.4-slim
,2-slim
2.4-alpine
,2-alpine
2.3
2.3-slim
2.3-alpine
2.2
2.2-slim
2.2-alpine
- Does not comes with any pre-installed version of rails, so you can choose by yourself
- Uses gosu to better handle su and sudo commands
- Automatically creates and prepares new rails app
- Runs bundle install & rake db:migrate on every restart for quick development
- For production modifies log output to stdout and formats it for Logstash
- In development adds docker network as trusted for web console
- Includes pry for easier debugging
- Solves problem with wrong permissions on shared volumes by matching UIDs
Execute this command in empty folder:
docker run -it -v $(pwd):/home/app/webapp -p 3000:3000 krismichalski/rails:latest
When you start this image, you can adjust some of the behavior by passing one or more environment variables.
Default: Based on ruby version.
Ruby version | Default rails version |
---|---|
2.4 | ~> 5.1 |
2.3 | ~> 5.0 |
2.2 | ~> 4.2 |
You can specify what version of rails you want to install.
Installation will occur once and only if run command wasn't
changed or it starts with rails
, rake
or bundle
.
Note: Has no effect in mini versions, because they have rails pre-installed.
Default: webapp
By default rails creates app name, which determines e.g. databases names, based on folder name where rails new command was run.
In case of this image it would be module Webapp
. This setting lets you overwrite this.
Default: [empty string]
You can specify additional arguments to rails new command.
For example RAILS_NEW_ARGS="--api --skip-spring"
Default: ,docker-compose.yml,.bundle,Dockerfile,.git,.svn,.hg
To avoid problems with overwriting files this image runs rails new command only if certain set of files is present in mounted volume. If anything besides these files is present rails new command will not be triggered.
Default: [empty string]
You can add additional files to white-list when checking for rails new command to run.
For example RAILS_NEW_IGNORED_FILES=Dockerfile.production,compose-production.yml
Default: 1000
You can change UID of default user to match your host user UID.
Default: false
You may wish to not run rails server after preparing app. To achieve this set this variable to true.
Default: sqlite3
Name of the database adapter to use with your app.
Notice: it's not value passed to rails new command, but to database.yml file.
Default: [empty string]
Address to your database server.
Default: [empty string]
User of your database.
Default: [empty string]
Password for your database user.
Consult official readme for difference between
<version>
, <version>-slim
and <version>-alpine
images.
These images are more of an experiment to create smallest, usable image for rails.
With the size about 150MB, these are ~4 times thinner than official rails images.
Instead of installing every single gem from Gemfile each time you want to add new one, I recommend to create docker volume and mount it to /home/app/bundle. Thanks to that you can install only new gems.
See example docker-compose.yml for a way to achieve this.
Also to avoid installing rails over and over again it's probably a good idea to place below Dockerfile in root of your app and use image build with it.
FROM krismichalski/rails:latest
ENV RAILS_VERSION=5.1.0
RUN /home/app/install_rails.sh
This image was tested with Docker version 17.04 and should work with any version above 1.11.2
I would be very pleased to hear whether or not it works on older versions as well.
If you have any problems with or questions about this image, please contact me through a GitHub issue.
You are invited to contribute new features, fixes, or updates, large or small.
I'm always thrilled to receive pull requests, and do my best to process them as fast as I can.
Released under the MIT License. See LICENSE file for details.