Skip to content

Instantly share code, notes, and snippets.

@kurenn
Created August 10, 2016 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurenn/1846d30274cb8de163259bd6a63ae8c5 to your computer and use it in GitHub Desktop.
Save kurenn/1846d30274cb8de163259bd6a63ae8c5 to your computer and use it in GitHub Desktop.
version: '2'
volumes:
postgres-data:
driver: local
gems:
driver: local
services:
db:
image: postgres:9.5.1
ports:
# We'll bind our host's port 5432 to postgres's port 5432, so we can use
# our database IDEs with it:
- 5432:5432
volumes:
# We'll store the postgres data in the 'postgres-data' volume we defined:
- postgres-data:/var/lib/postgresql/data
- ./db/dumps:/db/dumps:ro # Mount the DB dumps folder
- ./bin/restoredb:/bin/restoredb:ro # Mount the 'restoredb' script
environment:
POSTGRES_PASSWORD: P4Ssw0rD!
# The job processor container - we'll use this as a base for the rest of the
# containers:
web: &app
image: ruby:2.2.5
command: rails server -b 0.0.0.0 -p 3000 -P /tmp/rails.pid
ports:
- 3000:3000
# Specify the directory from where all commands sent to the container will be
# issued to where the code is mounted:
working_dir: /usr/src/app
entrypoint: /usr/src/app/dev-entrypoint
volumes:
# Mount our app code directory (".") into our app containers at the
# "/usr/src/app" folder:
- .:/usr/src/app
# Mount the 'gems' volume on the folder that stores bundled gems:
- gems:/usr/local/bundle
# Keep the stdin open, so we can attach to our app container's process
# and do things such as byebug, etc:
stdin_open: true
# Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
tty: true
# Link to our postgres and redis containers, so they can be visible from our
# app containers:
links:
# We'll include a link to the 'db' (postgres) container, making it
# visible from the container using the 'db' hostname:
- db
# Specify environment variables available for our app containers. We'll leave
# a YML anchor in case we need to override or add more variables if needed on
# each app container:
environment: &app_environment
# We'll overwrite the PATH environment variable to include the 'bin/'
# directory, for the entrypoint script to find the app's executables:
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# We'll set the DATABASE_URL environment variable for the app to connect
# to our postgres container - no need to use a 'config/database.yml' file.
DATABASE_URL: postgres://postgres:P4Ssw0rD!@db:5432/docker_rails_dev?pool=25&encoding=unicode&schema_search_path=public,partitioning
# We'll set the RAILS_ENV and RACK_ENV environment variables to
# 'development', so our app containers will start in 'development' mode
# on this compose project:
RAILS_ENV: development
RACK_ENV: development
# We'll specify a dotenv file for docker-compose to load more environment
# variables into our app containers. This dotenv file would normally contain
# sensitive data (API keys & secrets, etc) which SHOULD NOT be committed into
# Git.
# Keep in mind that any changes in this file will require a container restart
# in order to be available on the app containers:
env_file:
- dev.env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment