Created
July 2, 2019 19:59
-
-
Save luvpreetsingh/1a230bf2e4f36a2a1480f0ced15f0fc9 to your computer and use it in GitHub Desktop.
Dockerfile for django applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1.0.0-experimental | |
# The above comment is not to be deleted, its necessary. We are using an experimental feature and above line is important to enable that | |
# please refer to this, https://medium.com/@tonistiigi/build-secrets-and-ssh-forwarding-in-docker-18-09-ae8161d066 to know more about this | |
# before building docker image using this dockerfile, please do export DOCKER_BUILDKIT=1 | |
FROM python:3.6-alpine | |
ENV PYTHONUNBUFFERED 1 | |
WORKDIR /api/ | |
COPY ./requirements/requirements.txt ./requirements.txt | |
# the secrets are used if you are installing any private package in requirements | |
# installing essential packages for building and running packages | |
# the packages needed for build are later removed while the packages | |
# needed for running are kept | |
RUN --mount=type=secret,id=git_token,dst=/git_token export GIT_ACCESS_TOKEN=$(cat /git_token) \ | |
&& apk add --no-cache --virtual .build-deps \ | |
ca-certificates gcc postgresql-dev linux-headers musl-dev \ | |
libffi-dev jpeg-dev zlib-dev git \ | |
&& 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 \ | |
&& rm -rf src/my-package-name/.git/ # this command is only useful if you are installing a private package | |
# copying the code | |
COPY ./ ./ | |
## this command will run on container creation | |
ENTRYPOINT ["/bin/sh", "start.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment