Skip to content

Instantly share code, notes, and snippets.

Created November 1, 2017 10:12
Show Gist options
  • Save anonymous/ff9b51f403dcd6e45881f1166168566a to your computer and use it in GitHub Desktop.
Save anonymous/ff9b51f403dcd6e45881f1166168566a to your computer and use it in GitHub Desktop.
Example docker config for rails develompent
FROM ruby:2.4
## In case of postgresql for heroku:
# RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgeresql.list \
# && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
# && apt-get update \
# && apt-get update \
# && apt-get install -y --no-install-recommends \
# postgresql-client-9.6 pv ack-grep ccze unp htop vim \
# && rm -rf /var/lib/apt/lists/* \
# && apt-get purge -y --auto-remove
## In case of mysql for amazon RDS
RUN apt-get update \
&& apt-get update \
&& apt-get install -y --no-install-recommends mysql-client nodejs pv \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge -y --auto-remove
ENV BUNDLER_VERSION 1.15.3
RUN gem install bundler --version "$BUNDLER_VERSION"
WORKDIR /usr/src/app
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
version: '2'
services:
app: &app_base
build: .
working_dir: /usr/src/app
volumes:
- .:/usr/src/app
# to be able to forward ssh-agent to github throught capistrano (bundle on server)
- "~/.ssh/id_rsa:/root/.ssh/id_rsa"
- $SSH_AUTH_SOCK:$SSH_AUTH_SOCK
environment: &app_environment
TZ: Europe/Madrid
# to keep bundle effect between container restarts (withou rebuild):
BUNDLE_PATH: /usr/src/app/.bundle
BUNDLE_APP_CONFIG: /usr/src/app/.bundle
DATABASE_HOST: db
MEMCACHED_HOST: cache
SSH_AUTH_SOCK: # this left empty copies from outside env
command: 'bin/start'
ports:
- "3000:3000"
depends_on:
- db
- cache
- queue
queue:
# import app's config to run delayed_job workers
<<: *app_base
ports: [] # dont open 300 also, it would collide with app's
depends_on:
- db
- cache
environment:
<<: *app_environment
QUEUE: default
command: 'bin/start_queue'
cache:
image: memcached
ports:
- "11211"
db:
image: mysql:5.5
environment:
MYSQL_DATABASE: my_project_development
MYSQL_ROOT_PASSWORD: root
volumes:
# max_allowed_packet=32M' or any other custom config for mysql
- './config/mysql:/etc/mysql/conf.d/'
ports:
# expose the port on localhost to use db GUI
- "3306:3306"
## In case of postgres
# db:
# image: postgres
# ports:
# - "5432:5432"
# environment:
# POSTGRES_DB: my_project_development
# POSTGRES_USER: root
# POSTGRES_PASSWORD: root
#!/usr/bin/env bash
# bin/start
echo "Removing old server pid's if any..."
rm -f tmp/pids/server.pid
echo "Checking bundle dependencies..."
bundle check || bundle install
echo "Booting up..."
bundle exec rails s -p 3000 -b 0.0.0.0 -e development
#!/usr/bin/env bash
# bin/start_queue
echo "Removing old server pid's if any..."
rm -f tmp/pids/delayed*.pid
echo "Checking bundle dependencies..."
bundle check || bundle install
echo "Booting up..."
bundle exec bin/delayed_job run -n 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment