Skip to content

Instantly share code, notes, and snippets.

@Midnighter
Last active May 22, 2018 11:35
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 Midnighter/d3b6d9c1b5c270f4f48f36b3f98446c2 to your computer and use it in GitHub Desktop.
Save Midnighter/d3b6d9c1b5c270f4f48f36b3f98446c2 to your computer and use it in GitHub Desktop.
A minimal Python 3.6 Dockerfile intended for microservices that need libc. Sets up an unprivileged user and expects the use of pipenv, gunicorn, and gevent.
FROM python:3.6-slim
ENV PYTHONUNBUFFERED=1
ENV APP_USER=giraffe
ARG UID=1000
ARG GID=1000
ARG CWD=/app
ENV PYTHONPATH=${CWD}
RUN groupadd --system --gid "${GID}" "${APP_USER}" \
&& useradd --system --uid "${UID}" --gid "${APP_USER}" "${APP_USER}"
WORKDIR "${CWD}"
COPY . "${CWD}/"
RUN chown -R "${APP_USER}:${APP_USER}" "${CWD}"
# `g++` is required for building `gevent` but all build dependencies are
# later removed again.
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
g++ \
&& pip install --upgrade pip setuptools wheel pipenv \
&& pipenv install --dev --system --deploy \
&& rm -rf /root/.cache/pip \
&& apt-get purge --yes g++ \
&& apt-get autoremove --yes \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment