Last active
December 24, 2022 12:43
-
-
Save afrischk/9786927329811b7af75ab3fbdf4edcdd to your computer and use it in GitHub Desktop.
Example of a distroless python 3.10 image using pipenv.
This file contains 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
FROM python:3.10-slim as base | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONFAULTHANDLER 1 | |
FROM base AS python-deps | |
RUN pip install pipenv | |
COPY Pipfile . | |
COPY Pipfile.lock . | |
# create virtual environment | |
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy | |
#https://github.com/GoogleContainerTools/distroless/issues/973#issuecomment-1065169760 | |
FROM gcr.io/distroless/base-debian11:nonroot | |
WORKDIR /app | |
ARG ARCH=x86_64-linux-gnu | |
# copy necessary system libs | |
COPY --from=python-deps /lib/${ARCH}/libz.so.1 /lib/${ARCH}/libz.so.1 | |
# copy python 3.10 and relevant libs | |
COPY --from=python-deps /usr/local/bin/python3.10 /usr/local/bin/python3.10 | |
COPY --from=python-deps /usr/local/lib/libpython3.10.so.1.0 /usr/local/lib/libpython3.10.so.1.0 | |
COPY --from=python-deps /usr/local/lib/python3.10 /usr/local/lib/python3.10 | |
# copy packages | |
COPY --from=python-deps /.venv/lib/python3.10/site-packages /app/site-packages | |
# set envs | |
ENV PYTHONPATH /app/site-packages | |
ENV LD_LIBRARY_PATH /usr/local/lib | |
# copy program | |
COPY main.py . | |
EXPOSE 8080 | |
ENTRYPOINT ["python3.10", "main.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment