jmscholen / docker-rails

Base docker image for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nullstone/rails

Rails Base Image that is optimized for production and configured to operate locally the same way. This image is very opinionated; however, not restrictive.

Quick Reference

Supported Tags and respective Dockerfile links

Production vs Local

This repository builds an image for local use and production use.

The local image configures:

  • Sets the environment variable RAILS_ENV=development
  • On boot, the image runs bundle install (means you only need to restart the docker container when updating Gemfile)

Base image vs webapp image

This repository builds 2 variants of images: a base image and a webapp image.

The base image configures:

  • Server optimized for puma.
  • When making code changes locally, there is no need to rebuild/restart your container.
  • Logs are emitted to stdout.
  • Sets PORT env var to 80
  • On boot, POSTGRES_URL sets DB_ADAPTER=postgresql, DATABASE_URL=$POSTGRES_URL
  • On boot, MYSQL_URL sets DB_ADAPTER=mysql, DATABASE_URL=$MYSQL_URL

The webapp image additionally configures:

  • Preconfigures the image to attach nginx sidecar container. See below.
  • Changes PORT env var to 9000 to allow nginx to use port 80

Nginx sidecar

The webapp image is configured to optionally connect sidecar container running nginx. This pattern allows you to use nginx to serve static assets while the rails server serves dynamic requests.

docker-compose

See examples/webapp/prod.docker-compose.yml for a docker compose that mimics a production environment.

Nullstone

The following Nullstones modules provide one-click addition of an nginx sidecar:

Static Assets

Make sure to place all static content into /app/public inside the container. With a typical rails setup, this is done with the following in Dockerfile.

...
COPY . . # copies all rails code including `./public` into `/app`
RUN bundle exec rake assets:precompile
RUN bundle exec rake assets:clean

About

Base docker image for Rails


Languages

Language:Dockerfile 43.6%Language:Makefile 33.2%Language:Shell 23.2%