Skip to content

Instantly share code, notes, and snippets.

@anderkonzen
Created November 14, 2019 00:33
Show Gist options
  • Save anderkonzen/8be9b9145f7c9139186d42374c4c42b5 to your computer and use it in GitHub Desktop.
Save anderkonzen/8be9b9145f7c9139186d42374c4c42b5 to your computer and use it in GitHub Desktop.
Dockerfile for Rails development
FROM ruby:2.3.8-stretch
# To build this image, use:
# docker build -f Dockerfile-dev -t rails-dev .
#
# To run a console with the current directory mounted
# in the container, use:
# docker run -it --rm -v `pwd`:/app rails-dev bundle exec rails c
#
# To run a shell:
# docker run -it --rm -v `pwd`:/app rails-dev bash
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
jpegoptim \
ghostscript \
optipng \
libpng-dev \
libtiff-dev \
libwebp-dev \
imagemagick \
zip \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
# Copy the main application.
COPY . ./
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment