Created
June 10, 2021 09:28
-
-
Save radimih/be7aa5faa04b45ca1f3da358d1ed8ece to your computer and use it in GitHub Desktop.
Dockerfile for Python project
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
| # Исключить все файлы и каталоги | |
| ** | |
| # ... кроме следующих: | |
| !Pipfile | |
| !Pipfile.lock | |
| !main.py |
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
| #------------------------------------------------------------------------------- | |
| FROM python:3.9-slim AS base | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONFAULTHANDLER=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV LANG=C.UTF-8 | |
| ENV LC_ALL=C.UTF-8 | |
| # ------------------------------------------------------------------------------ | |
| FROM base AS python-deps | |
| # Установить pipenv и компилятор, необходимый для установки некоторых библиотек | |
| RUN pip install pipenv | |
| RUN apt-get update && apt-get install -y --no-install-recommends gcc | |
| # Установить Python-зависимости приложения в каталог /.venv | |
| COPY Pipfile . | |
| COPY Pipfile.lock . | |
| RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy | |
| # ------------------------------------------------------------------------------ | |
| FROM base AS runtime | |
| # Скопировать ранее установленные Python-зависимости приложения | |
| COPY --from=python-deps /.venv /.venv | |
| ENV PATH="/.venv/bin:$PATH" | |
| # Создать системного пользователя и переключиться на него | |
| RUN useradd --system --shell /bin/false --home-dir /nonexistent --no-create-home appuser | |
| USER appuser | |
| # Скопировать файлы приложения в образ (см. .dockerignore) | |
| WORKDIR /opt/app | |
| COPY . . | |
| ENTRYPOINT ["python", "main.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment