Skip to content

Instantly share code, notes, and snippets.

@vovimayhem
Last active February 25, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vovimayhem/ce0c78e549eff07bb7c5f9f44784ef0a to your computer and use it in GitHub Desktop.
Save vovimayhem/ce0c78e549eff07bb7c5f9f44784ef0a to your computer and use it in GitHub Desktop.
Example of a development dockerfile & compose replicating the host's user
# Other parts of the file omitted for clarity:
version: "2.4"
services:
# The test container - we'll use this as a base for the rest of the containers:
test: &app
image: vovimayhem/example-app:development
build:
context: .
dockerfile: Dockerfile
target: development
args:
- DEVELOPER_UID=${UID:-1000}
- DEVELOPER_USER=${USER:-you}
entrypoint: /usr/src/bin/dev-entrypoint.sh
command: rspec
networks: [ "backend" ]
depends_on: [ "postgres" ]
volumes:
# Mount our app code directory (".") into our app containers at the
# "/usr/src" folder:
- .:/usr/src
# Keep the stdin open, so we can attach to our app container's process
# and do things such as byebug, etc:
stdin_open: true
# Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
tty: true
# Specify environment variables available for our app containers. We'll leave
# a YML anchor in case we need to override or add more variables if needed on
# each app container:
environment: &app_env
DATABASE_URL: postgres://postgres:3x4mpl3P455w0rd@postgres:5432/blackcomb_test
RAILS_ENV: test
RACK_ENV: test
RAILS_LOG_TO_STDOUT: 'true'
MAILER_HOST: localhost
MAILER_PORT: 3000
# Other parts of the file omitted for clarity:
# I: Runtime Stage: ============================================================
FROM ruby:2.6.1-alpine AS runtime
WORKDIR /usr/src
ENV HOME=/usr/src PATH=/usr/src/bin:$PATH
RUN apk add --no-cache ca-certificates less libpq nodejs npm openssl su-exec tzdata
# II: Development Stage: =======================================================
FROM runtime AS development
RUN apk add --no-cache \
build-base \
chromium \
chromium-chromedriver \
git \
postgresql-dev \
yarn
RUN npm config set unsafe-perm true
RUN npm install -g check-dependencies
ADD Gemfile* /usr/src/
RUN bundle install --jobs=4 --retry=3
ARG DEVELOPER_UID="1000"
ARG DEVELOPER_USER="you"
RUN adduser -H -D -h /usr/src -u $DEVELOPER_UID $DEVELOPER_USER \
&& addgroup $DEVELOPER_USER root
ENV DEVELOPER_USER=$DEVELOPER_USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment