Docker-контейнер Django не подключается к postgresql
У меня проблемы с запуском приложения django. Кажется, что оно замирает, когда выводит
"Проверка системы выявила 6 проблем (0 заглушены)."
Я полагаю, что это происходит потому, что django не подключен к базе данных postgresql. Я действительно не знаю, в чем может быть проблема, потому что год назад он работал нормально, а когда я запускаю его сейчас, он ломается.
Вот вывод для postgresql из журнала контейнера docker
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2022-06-13 03:35:26.151 UTC [48] LOG: received fast shutdown request
waiting for server to shut down....2022-06-13 03:35:26.155 UTC [48] LOG: aborting any active transactions
2022-06-13 03:35:26.156 UTC [48] LOG: background worker "logical replication launcher" (PID 55) exited with exit code 1
2022-06-13 03:35:26.156 UTC [50] LOG: shutting down
2022-06-13 03:35:26.204 UTC [48] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
2022-06-13 03:35:26.273 UTC [1] LOG: starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-06-13 03:35:26.273 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-06-13 03:35:26.273 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-06-13 03:35:26.281 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-06-13 03:35:26.290 UTC [60] LOG: database system was shut down at 2022-06-13 03:35:26 UTC
2022-06-13 03:35:26.291 UTC [61] FATAL: the database system is starting up
2022-06-13 03:35:26.297 UTC [1] LOG: database system is ready to accept connections
django docker logs:
File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: the database system is starting up
Вот мой docker-compose.yml файл
version: "3.7"
services:
postgresql:
container_name: postgresql
image: postgres:14.3-bullseye
restart: always
volumes:
- postgresql_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=12345678
django:
container_name: django
build: .
# command: ENTERYPOINT
volumes:
- static_volume:/app/static
depends_on:
- postgresql
nginx:
container_name: nginx
build: ./nginx/.
volumes:
- static_volume:/app/static
ports:
- "80:80"
- "443:443"
depends_on:
- django
volumes:
static_volume:
postgresql_data:
Настройки Django для базы данных docker postgresql
# docker database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '12345678',
'HOST': 'postgresql',
'PORT': 5432,
}
}
Django Dockerfile
FROM python:3.9-buster
WORKDIR /app
RUN apt update && apt upgrade -y
RUN pip install -U pip
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app/
COPY ./django-enterypoint.sh /app/
ENTRYPOINT [ "sh", "django-enterypoint.sh" ]
Файл Django django-enterypoint.sh
python manage.py collectstatic --no-input
python manage.py migrate --no-input
python manage.py runserver 0.0.0.0:8000
# gunicorn wall.wsgi:application --bind 0.0.0.0:8000