Skip to content

Instantly share code, notes, and snippets.

@ncopa
Created April 15, 2016 12:37
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ncopa/d7c2e816fb09066022ba4e723621bef8 to your computer and use it in GitHub Desktop.
Save ncopa/d7c2e816fb09066022ba4e723621bef8 to your computer and use it in GitHub Desktop.
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()"
@nickjj
Copy link

nickjj commented Apr 15, 2016

Thanks. Your gist has been incorporated (and credited) into http://nickjanetakis.com/blog/alpine-based-docker-images-make-a-difference-in-real-world-apps.

@JoeAlamo
Copy link

With this example, what if a binary exists in /usr/bin and not /usr/local? Won't it's dependencies get wiped out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment