This is my basic Rails app template for beginning development with Docker.
- Rails version: 4.2.1
- Ruby version: 2.2.0
Docker images used:
It runs the application as the app
user. The database owner is the
myapp_user
. To customize this template, grep for myapp
and replace all
occurrences.
First, decide which environment you wish to use. Copy the selected environment
file into .env
. For example:
cp .env.development .env
Be sure to define any of the environment variables without values.
Any added environment variables must also be added to rails-env.conf
so that
they're exposed to Nginx child processes (more info).
Docker Compose is used for linking containers.
First, build the included Dockerfiles:
docker-compose build
Then, start the web app:
docker-compose up
Finally, create the database:
docker exec myapp_web_1 bin/rake db:create
Further commands can be executed in this way.
The app is exposed on port 80 by default. If using Boot2Docker, enter its IP address in your browser.
This template uses Sidekiq for background
processing. A Redis container is linked to enable Sidekiq to work. Once the app
is started, Sidekiq provides a monitoring tool at /sidekiq
.
To start Sidekiq and process jobs: bin/sidekiq
Sidetiq is used to create scheduled
jobs. Scheduled jobs should go under app/workers/scheduled/
and will be
automatically loaded even in the development environment.
For TDD, this template includes the following:
Be sure to create:
SECRET_BASE_KEY
viabin/rake secret
myapp_prod_user
with a password forMYAPP_PROD_USER_DATABASE_PASSWORD
docker-compose up
will create a Docker 'web' container named <base-directory-name>_web_1
.
The following Bash function:
# ddo -> 'docker-do'
function ddo { docker exec -it `basename $PWD | sed s/[-_]//g`_web_1 $* }
allows:
# Create the database
ddo bin/rake db:create
# Run specs
ddo bin/rspec
# Start a Bash login shell
ddo bash -l