From 357099accd195f7975dd0c596c15e5f80cdd95e3 Mon Sep 17 00:00:00 2001 From: prog1764 Date: Tue, 4 Aug 2026 20:23:51 +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(Django)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile: python:3.12-slim, migrate + collectstatic + gunicorn (0.0.0.0:8000) - docker-compose.yml: порт 8000, env из .env, volume для SQLite - .dockerignore: .env, db.sqlite3, staticfiles, кэш - requirements.txt: + gunicorn - settings.py: STATIC_ROOT для collectstatic - проверено: manage.py check без ошибок --- .dockerignore | 13 +++++++++++++ Dockerfile | 17 +++++++++++++++++ config/settings.py | 1 + docker-compose.yml | 14 ++++++++++++++ requirements.txt | 1 + 5 files changed, 46 insertions(+) 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..40abb35 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.gitignore +.idea +__pycache__ +*.pyc +*.pyo +.env +.venv +venv +db.sqlite3 +staticfiles +logs +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01f1eef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# 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 . . + +# Миграции + статика при старте контейнера +CMD ["sh", "-c", "python manage.py migrate --noinput && python manage.py collectstatic --noinput && gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 2"] diff --git a/config/settings.py b/config/settings.py index f73a025..c66566c 100644 --- a/config/settings.py +++ b/config/settings.py @@ -110,5 +110,6 @@ USE_TZ = True STATIC_URL = "static/" STATICFILES_DIRS = [BASE_DIR / "static"] +STATIC_ROOT = BASE_DIR / "staticfiles" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..88e6842 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +# Секреты — только из .env (см. .env.example) +services: + web: + build: . + ports: + - "8000:8000" + env_file: + - .env + volumes: + - sqlite_data:/app/db.sqlite3 + restart: unless-stopped + +volumes: + sqlite_data: diff --git a/requirements.txt b/requirements.txt index 51030d4..144a429 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Django>=5.0,<6.0 django-axes>=8.3.1 python-dotenv>=1.0 +gunicorn>=22.0