Skip to content

Instantly share code, notes, and snippets.

@fotinakis
Created November 23, 2014 20:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fotinakis/04077671bec4edf77c08 to your computer and use it in GitHub Desktop.
Save fotinakis/04077671bec4edf77c08 to your computer and use it in GitHub Desktop.
Docker + fig with mounted volume for dev environment (and correctly handles bundle install).
# Running these will now correctly update the Gemfile.lock in the mounted host folder:
$ fig run web bundle install
$ fig run web bundle update <gemname>
# Base image.
FROM fotinakis/baseimage-ruby:2.1.3
# System dependencies for gems.
RUN apt-get update
RUN apt-get install -y --no-install-recommends libmysqlclient-dev
# Add 'web' user which will run the application.
RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos ""
# Add directory where all application code will live and own it by the web user.
RUN mkdir /app
RUN chown -R web:web /app
# Install gems separately here to take advantage of container caching of `bundle install`.
# Also, ensure that gems are installed as the web user and not system-wide so that we can run
# `fig web bundle install` and the web user will have permissions to update the shared Gemfile.lock.
ADD Gemfile /app/
ADD Gemfile.lock /app/
RUN chown -R web:web /app
USER web
ENV HOME /home/web
ENV PATH $PATH:/home/web/.gem/ruby/2.1.0/bin
ENV GEM_HOME /home/web/.gem/ruby/2.1.0
ENV GEM_PATH $GEM_HOME
RUN gem install --user-install bundler
WORKDIR /app/
RUN bundle install
USER root
# Add the whole application source to the image and own it all by web:web.
# Note: this is overwritten in development because fig mounts a shared volume at /app.
ADD . /app/
RUN chown -R web:web /app
# Clean up APT and /tmp when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Default command to run when this container is run.
USER web
WORKDIR /app/
CMD ["bundle", "exec", "rails", "server"]
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: fizzbuzz
ports:
- 3306
web:
build: .
volumes:
- .:/app
ports:
- 3000:3000
links:
- db
@fotinakis
Copy link
Author

Related fig issue: docker/compose#222 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment