Докеризация Django с помощью nginx и gunicorn

Это очень базовое развертывание django, и я пытаюсь настроить nginx и gunicorn на нем через docker

Вроде бы все работает нормально, но нет соединения.

путь к папке:

 Dockerized-Django
├── Dockerfile
├── docker-compose.yml
├── entrypoint.sh
├── nginx
│   ├── Dockerfile
│   └── default.conf
├── pyshop
│   ├── db.sqlite3
│   ├── manage.py
│   ├── products
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-38.pyc
│   │   │   ├── admin.cpython-38.pyc
│   │   │   ├── apps.cpython-38.pyc
│   │   │   ├── models.cpython-38.pyc
│   │   │   ├── urls.cpython-38.pyc
│   │   │   └── views.cpython-38.pyc
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0002_offer.py
│   │   │   ├── 0003_auto_20220507_1845.py
│   │   │   ├── __init__.py
│   │   │   └── __pycache__
│   │   │       ├── 0001_initial.cpython-38.pyc
│   │   │       ├── 0002_offer.cpython-38.pyc
│   │   │       ├── 0003_auto_20220507_1845.cpython-38.pyc
│   │   │       └── __init__.cpython-38.pyc
│   │   ├── models.py
│   │   ├── templates
│   │   │   ├── base.html
│   │   │   └── index.html
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   └── pyshop
│       ├── __init__.py
│       ├── __pycache__
│       │   ├── __init__.cpython-38.pyc
│       │   ├── settings.cpython-38.pyc
│       │   ├── urls.cpython-38.pyc
│       │   └── wsgi.cpython-38.pyc
│       ├── settings.py
│       ├── urls.py
│       └── wsgi.py
├── requirements.txt
└── test.py

docker-compose.yml:

version: '3.7'

services:
  pyshop_gunicorn:
    volumes:
      - static:/static
    env_file:
      - .env
    build:
      context: .
    ports:
      - "8000:8000"
  nginx:
    build: ./nginx
    volumes:
      - static:/static
    ports:
      - "80:80"
    depends_on:
      - pyshop_gunicorn

volumes:
  static:

главный докерфайл:

FROM python:3.8.5-alpine
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY ./pyshop /app
WORKDIR /app
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]

entrypoint.sh:

#!/bin/sh

python manage.py migrate --no-input
python manage.py collectstatic --no-input


gunicorn pyshop.wsgi:application --bind 0.0.0.0:8000

nginx conf:

upstream django {
    server pyshop_gunicorn:8000;
}

server {
    listen 80;

    location / {
        proxy_pass http://django;
    }

    location /static/ {
        alias /static/;
    }
}

nginx Dockerfile:

FROM nginx:1.19.0-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf

.env файл содержит

SECRET_KEY='secret'
DEBUG=True

setting.py под Django/pyshop/pyshop

STATIC_ROOT = '/static/'
ALLOWED_HOSTS = ['*']
DEBUG = os.getenv('DEBUG')
SECRET_KEY = os.getenv('SECRET_KEY')

docker container ls:

CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                    NAMES
69d6c855bcee   django_nginx             "/docker-entrypoint.…"   4 minutes ago   Up 4 minutes   0.0.0.0:80->80/tcp       django_nginx_1
9946bdb2b1c9   django_pyshop_gunicorn   "sh /entrypoint.sh"      4 minutes ago   Up 4 minutes   0.0.0.0:8000->8000/tcp   django_pyshop_gunicorn_1

docker-compose up --build:

Похоже, что нет соединения с 0.0.0.0:8000

Вернуться на верх