Skip to content

Instantly share code, notes, and snippets.

@tigefa4u
Created September 10, 2018 03:13
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 tigefa4u/b95c88c7c81624e9f77c5dcbf5cffd75 to your computer and use it in GitHub Desktop.
Save tigefa4u/b95c88c7c81624e9f77c5dcbf5cffd75 to your computer and use it in GitHub Desktop.
Ruby and Rails docker example
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: mysql
MYSQL_PASSWORD: password
web:
build: .
links:
- db
volumes:
- .:/home/ticketbuster/repo
ports:
- '3000:3000'
env_file:
- .env
restart: always
command: foreman start
FROM ruby:2.3.1-alpine
MAINTAINER Keifer Furzland <kfrz.code@gmail.com>
# Env
ENV REFRESHED_AT 2016-09-21
ENV REPO_DIR /home/ticketbuster/repo
ENV GEM_HOME /home/ticketbuster/gems
ENV ENV_FILE /home/ticketbuster/repo/.env
ENV BUILD_PACKAGES bash libffi-dev openssl-dev linux-headers zlib-dev readline-dev yaml-dev git curl-dev ruby-dev build-base
ENV RUBY_PACKAGES ruby-io-console ruby-bundler nodejs libxml2-dev mysql-dev mariadb-dev
RUN apk update && \
apk upgrade && \
apk add $BUILD_PACKAGES && \
apk add $RUBY_PACKAGES && \
rm -rf /var/cache/apk/*
# We're adding a specific GID and UID so we can seamlessly scale to clusters
# Also we want to run the app as this user for great justice
# -D says no password -- this maybe should change, although docker is isolated as it is.
#RUN addgroup -g 7891 ticketbuster && \
# adduser -h /home/ticketbuster -s /bin/false -u 7892 -G ticketbuster ticketbuster -D
# Create and switch to repo dir
RUN mkdir -p $GEM_HOME $REPO_DIR
WORKDIR $REPO_DIR
# Copy the rest of the app
# RUN git clone ssh://git@gitlab.com:kfrz/ticketbuster.git
ADD . $REPO_DIR
# Symlink vendor
RUN ln -sn /home/ticketbuster/repo/vendor/bundle $GEM_HOME
#RUN chown -R ticketbuster:ticketbuster $REPO_DIR && chown -R ticketbuster:ticketbuster $GEM_HOME && chmod -R a+w $REPO_DIR && chmod -R a+w 0644 $GEM_HOME
#USER ticketbuster
# Install gems. Bundler won't allow us to install with documentation.
#### NOTE: In production, the bundle command should be appended with `--without development test`
COPY Gemfile* $REPO_DIR/
RUN gem install bundle && gem install tzinfo-data && bundle install --jobs=6 --path=$GEM_HOME
# Provide a Healthcheck for Docker risk mitigation
HEALTHCHECK --interval=3600s --timeout=20s --retries=2 CMD curl http://localhost:3000 || exit 1
# Define an entrypoint for default
ENTRYPOINT ["bundle", "exec"]
# Default command, running app as a service
CMD ["bundle", "exec", "foreman", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment