Skip to content

Instantly share code, notes, and snippets.

@esys
Created October 27, 2020 15:54
Show Gist options
  • Save esys/26e65eb89a245c2b333c10a25e73f355 to your computer and use it in GitHub Desktop.
Save esys/26e65eb89a245c2b333c10a25e73f355 to your computer and use it in GitHub Desktop.
Python Flask HelloWorld Dockerfile
FROM python:3.7-alpine as builder
# install dependencies required to build python packages
RUN apk update && apk add --no-cache make gcc && pip install --upgrade pip
# setup venv and download or build dependencies
ENV VENV="/venv"
ENV PATH="${VENV}/bin:${PATH}"
COPY requirements.txt .
RUN python -m venv ${VENV} \
&& pip install --no-cache-dir -r requirements.txt
FROM python:3.7-alpine
# setup venv with dependencies from the builder stage
ENV VENV="/venv"
ENV PATH="${VENV}/bin:$PATH"
COPY --from=builder ${VENV} ${VENV}
# copy app files
WORKDIR /app
COPY app .
# run the app
EXPOSE 5000
ENV FLASK_APP="hello.py"
CMD [ "flask", "run", "--host=0.0.0.0" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment