Skip to content

Instantly share code, notes, and snippets.

@soreana
Created March 22, 2019 22:47
Show Gist options
  • Save soreana/74cb3dc6da24c523e426145a23b8bf95 to your computer and use it in GitHub Desktop.
Save soreana/74cb3dc6da24c523e426145a23b8bf95 to your computer and use it in GitHub Desktop.
Docker master pieces
### Slim version
FROM python:2.7-slim
MAINTAINER Nick Janetakis <nick.janetakis@gmail.com>
RUN apt-get update && apt-get install -qq -y \
build-essential libpq-dev libffi-dev --no-install-recommends
ENV INSTALL_PATH /bsawf
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD gunicorn -b 0.0.0.0:8000 --access-logfile - "bsawf.app:create()"
### Alpine based Dockerfile
FROM python:2.7-alpine
MAINTAINER Nick Janetakis <nick.janetakis@gmail.com>
RUN apk update && apk add build-base postgresql-dev libffi-dev
ENV INSTALL_PATH /bsawf
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD gunicorn -b 0.0.0.0:8000 --access-logfile - "bsawf.app:create()"
### Optimized Alpine based Dockerfile
FROM python:2.7-alpine
MAINTAINER Nick Janetakis <nick.janetakis@gmail.com>
ENV INSTALL_PATH /bsawf
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN apk add --no-cache --virtual .build-deps \
build-base postgresql-dev libffi-dev \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps
COPY . .
CMD gunicorn -b 0.0.0.0:8000 --access-logfile - "bsawf.app:create()"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment