Skip to content

Instantly share code, notes, and snippets.

@icarus44-zer0
Created June 6, 2022 18:04
Show Gist options
  • Save icarus44-zer0/495cffc6fb0107b0c84edb809f9ebf23 to your computer and use it in GitHub Desktop.
Save icarus44-zer0/495cffc6fb0107b0c84edb809f9ebf23 to your computer and use it in GitHub Desktop.
python:3.8.5-slim-buster- multi-stage - non-root - virtualenv
FROM python:3.8.5-slim-buster as base
LABEL maintainer="Your Name <[email protected]>" \
version="1.0.0"
RUN apt-get update && apt-get install tzdata -y --no-install-recommends
ENV TZ="America/Los_Angeles"
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PYTHONDONTWRITEBYTECODE=1
FROM base as builder
RUN adduser worker
USER worker
WORKDIR /home/worker
COPY --chown=worker:worker requirements.txt /home/worker/requirements.txt
ENV PATH="/home/worker/.local/bin:$PATH"
ENV PATH="/home/worker/venv/bin:$PATH"
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install --upgrade setuptools && \
python3 -m pip install virtualenv
RUN python3 -m venv /home/worker/venv
RUN pip install -r requirements.txt
FROM base
RUN adduser worker
USER worker
WORKDIR /home/worker
COPY --from=builder /home/worker /home/worker
COPY --from=builder /home/worker/venv /home/worker/venv
COPY --chown=worker:worker . .
ENV PATH="/home/worker/venv/bin:$PATH"
ENTRYPOINT ["python"]
CMD ["src/main.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment