docker: подготовка к запуску в контейнере (Flask)

- Dockerfile: python:3.12-slim, зависимости отдельным слоем
- docker-compose.yml: порт 5000, env из .env
- .dockerignore: .env, .git, кэш
- app.py: bind 0.0.0.0:5000 (в контейнере)
This commit is contained in:
2026-08-04 20:20:54 +04:00
parent 0c6740ac53
commit 0b48746e67
4 changed files with 46 additions and 1 deletions
+11
View File
@@ -0,0 +1,11 @@
.git
.gitignore
.idea
__pycache__
*.pyc
*.pyo
.env
.venv
venv
*.log
logs
+21
View File
@@ -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"]
+5 -1
View File
@@ -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",
)
+9
View File
@@ -0,0 +1,9 @@
# Секреты — только из .env (см. .env.example)
services:
web:
build: .
ports:
- "5000:5000"
env_file:
- .env
restart: unless-stopped