Skip to content

Instantly share code, notes, and snippets.

@SwamiRama
Last active June 17, 2016 18:50
Show Gist options
  • Save SwamiRama/0b651c2e66dae829a5cd1240b8e529b9 to your computer and use it in GitHub Desktop.
Save SwamiRama/0b651c2e66dae829a5cd1240b8e529b9 to your computer and use it in GitHub Desktop.
Rails in Docker
docker-compose build
docker-compose up
docker-compose run app rake db:create
docker-compose run app rake db:migrate
default: &default
adapter: postgresql
pool: 5
timeout: 5000
username: postgres
host: db
port: 5432
development:
<<: *default
database: app_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: app_test
production:
<<: *default
database: app
app:
build: .
command: rails server -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
links:
- db
db:
image: postgres:9.5
ports:
- "5432"
FROM ruby:2.3
MAINTAINER [email protected]
# 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
# 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
# Configure an entry point, so we don't need to specify
# "bundle exec" for each of our commands.
ENTRYPOINT ["bundle", "exec"]
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["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