From 0b48746e67486d26d11ec566902d9da3a2238f79 Mon Sep 17 00:00:00 2001 From: QA Tester Date: Tue, 4 Aug 2026 20:20:54 +0400 Subject: [PATCH] =?UTF-8?q?docker:=20=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D1=83=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D0=B9=D0=BD=D0=B5=D1=80=D0=B5=20(Flask)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile: python:3.12-slim, зависимости отдельным слоем - docker-compose.yml: порт 5000, env из .env - .dockerignore: .env, .git, кэш - app.py: bind 0.0.0.0:5000 (в контейнере) --- .dockerignore | 11 +++++++++++ Dockerfile | 21 +++++++++++++++++++++ app.py | 6 +++++- docker-compose.yml | 9 +++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ec4e39e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.gitignore +.idea +__pycache__ +*.pyc +*.pyo +.env +.venv +venv +*.log +logs diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..35c1e54 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Python 3.12 slim +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Сначала зависимости — чтобы кэшировать слой +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Код приложения +COPY . . + +# Не dev-режим по умолчанию +ENV FLASK_DEBUG=0 + +EXPOSE 5000 + +CMD ["python", "app.py"] diff --git a/app.py b/app.py index 9a0a7ae..f4f6f47 100644 --- a/app.py +++ b/app.py @@ -379,4 +379,8 @@ init_database() if __name__ == "__main__": - app.run(debug=os.environ.get("FLASK_DEBUG") == "1") + app.run( + host="0.0.0.0", + port=5000, + debug=os.environ.get("FLASK_DEBUG") == "1", + ) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3bfa8cd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +# Секреты — только из .env (см. .env.example) +services: + web: + build: . + ports: + - "5000:5000" + env_file: + - .env + restart: unless-stopped