Skip to content

Instantly share code, notes, and snippets.

@crohr
Created July 23, 2015 13:37
Show Gist options
  • Save crohr/7a0ddfe8767a6f0eaea9 to your computer and use it in GitHub Desktop.
Save crohr/7a0ddfe8767a6f0eaea9 to your computer and use it in GitHub Desktop.
Fully-working Dockerfile for a Rails app
FROM ruby:2.1
RUN apt-get update && apt-get install -y nodejs
RUN mkdir -p /usr/src/app
RUN useradd -d /usr/src/app -m app
RUN chown -R app /usr/src/app
RUN chown -R app /usr/local/bundle
USER root
WORKDIR /usr/src/app
COPY Gemfile ./Gemfile
COPY Gemfile.lock ./Gemfile.lock
RUN chown -R app.app .
USER app
RUN bundle install
USER root
COPY . /usr/src/app
RUN chown -R app.app .
USER app
RUN RAILS_ENV=production bundle exec rake assets:precompile --trace
CMD ["rails","server","-b","0.0.0.0"]
@crohr
Copy link
Author

crohr commented Jul 23, 2015

This correctly handles both production and development mode, in that in development mode you would mount your local copy of the code with:

docker build -t openproject:dev .
docker run -it -v $(pwd):/usr/src/app openproject:dev

The precompiled assets in public/assets would thus be erased, and subsequent bundle install would reuse the ones already installed in /usr/local/bundle.

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