Created
September 10, 2018 03:13
-
-
Save tigefa4u/b95c88c7c81624e9f77c5dcbf5cffd75 to your computer and use it in GitHub Desktop.
Ruby and Rails docker example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.3.1-alpine | |
MAINTAINER Keifer Furzland <[email protected]> | |
# 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://[email protected]: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