I'm trying to launch my django app inside docker container
docker-compose.yml
version: '3.8'
services:
api:
build:
context: .
dockerfile: ./Dockerfile-local
ports:
- "8000:8000"
entrypoint: ./entrypoint-local.sh
env_file:
- .env-local
links:
- postgresql
postgresql:
image: postgres:12.4
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_DB=frov_db
- POSTGRES_PASSWORD=postgres
- POSTGRES_HOST=postgresql
- POSTGRES_PORT=5432
- PGDATA=/var/lib/postgresql/data/pgdata
- C_FORCE_ROOT=true
ports:
- '5433:5432'
Dockerfile-local
FROM python:3.8-slim
ENV PYTHONDONTWRITEBYTECODE 1
WORKDIR /usr/src/app
COPY Pipfile.lock Pipfile ./
RUN pip install -U setuptools pip pipenv && pipenv install --system --deploy --ignore-pipfile --dev
COPY . .
RUN touch /var/log/filebeat.log && chmod 664 /var/log/filebeat.log \
&& chmod +x ./entrypoint-local.sh
entrypoint-local.sh
#!/bin/bash
python manage.py collectstatic --no-input --settings frov.settings.default
python manage.py migrate --settings frov.settings.default
python manage.py seed
gunicorn -b 0.0.0.0:8000 --workers=1 --env DJANGO_SETTINGS_MODULE=frov.settings.default frov.wsgi:application
.env-local
DEBUG=True
DJANGO_SETTINGS_MODULE=frov.settings.default
DB_NAME=frov_db
DB_USER=postgres
DB_PASS=postgres
DB_HOST=postgresql
DB_PORT=5433
And now I have now idea, why do I get such error
api_1 | psycopg2.OperationalError: could not connect to server: Connection refused
api_1 | Is the server running on host "postgresql" (172.21.0.2) and accepting
api_1 | TCP/IP connections on port 5433?
Can anyone hepls me? I just can't figure out where the mistake can take place
5433is the port exposed to the host. Inside docker network the postgres is still accessible bypostgresql:5432, so try to switch the port in the env to54325432is a container port exposed as5433host port. However, even docs refer to5433port asthe publicly exposed port. So I apologize for confusion, but I don't think I'm wrong here.