1

I dockerize my django backend app. I am using posgresql as db. After doing docker-compose up the last logs are:

db_1       | 2021-12-21 18:39:58.213 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1       | 2021-12-21 18:39:58.213 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1       | 2021-12-21 18:39:58.310 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2021-12-21 18:39:58.476 UTC [42] LOG:  database system was shut down at 2021-12-21 18:39:58 UTC
db_1       | 2021-12-21 18:39:58.678 UTC [1] LOG:  database system is ready to accept connections

I am not getting any other logs after them,I don't know what the issue is maybe its due to postgresql. But django server is not starting. I did docker ps I got following results

CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
d92379ca89b7   prodlerbackend_prodler   "python manage.py ru…"   20 minutes ago   Up 20 minutes   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp   prodlerbackend_prodler_1
3364c1cda344   postgres:11.2-alpine     "docker-entrypoint.s…"   20 minutes ago   Up 20 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   prodlerbackend_db_1

I think the containers are up, still Django server is not started what can be the issue?

docker-compose.yml

version: "3.9"

services:
  db:
    image: postgres:11.2-alpine
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    environment:
      - HOST=localhost
      - POSTGRES_DB=prodler
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=admin123
    ports:
      - 5432:5432
  prodler:
    build:
      context: .
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
Usama Hameed
  • 129
  • 5
  • 14
  • 1
    It looks like it's running, what response do you get when you access `http://localhost:8000`? – Iain Shelvington Dec 21 '21 at 19:22
  • Does this solve your issue? https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker – Iain Shelvington Dec 21 '21 at 19:24
  • I am not getting any response when going to localhost:8000. Web page is not opening – Usama Hameed Dec 21 '21 at 19:49
  • If you try to run the prodler container yourself, do you get any output then? `docker compose run --rm prodler python -u manage.py runserver 0.0.0.0:8000` – Iain Shelvington Dec 21 '21 at 20:30
  • no, its giving this error: "could not connect to server: Cannot assign requested address Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?" – Usama Hameed Dec 21 '21 at 20:43
  • What is your DATABASES setting? To connect to the postgres container from your django container you need to use "db" as the host not "localhost", you use the service name as the hostname, this also means you may have to change the HOST env var for your db service to "db" – Iain Shelvington Dec 21 '21 at 20:46

1 Answers1

0

You need to change your connection details in the config to connect to postgres:5432

spod
  • 21
  • 3