0

I need to run my database in the first place, because when I do docker-compose up I got this error, because database isn't running yet:

django.db.utils.OperationalError: connection to server at "db" (172.27.0.2), port 5432 failed: Connection refused test-task-web-1 | Is the server running on that host and accepting TCP/IP connections?

Dockerfile:

FROM python:3.11-alpine

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . .

CMD ["python", "backend/manage.py", "runserver"]

docker-compose:

version: "3.9"
services:
  db:
    image: postgres:15.4-alpine
    expose:
      - "5432"
    environment:
      POSTGRES_DB: referal-api
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./data:/var/lib/postgresql/data

  web:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    ports:
      - "8000:8000"
    depends_on:
      - db
    links:
      - db:db
  • What's the issue here, since you are already using `depends_on` https://docs.docker.com/compose/compose-file/05-services/#depends_on? – Robin Thomas Aug 19 '23 at 05:11

0 Answers0