Подключение к серверу на "localhost" не удалось в Docker - Django [duplicate]

Я очень новичок в Docker и пытаюсь создать его для моего приложения django. но я столкнулся с ошибкой "Is the server running on that host and accepting TCP/IP connections?connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address". Я пробовал this и this и this . В основном все, что я смог найти, но все равно не работает. Docker-compose

version: '1'

services:
  web:
    build: .
    container_name: evident_django
    hostname: evident_django
    restart: always
    image: evident:latest
    volumes:
      - ./logs:/var/log/evident
      - ./src:/code
      - static_volume:/code/static
    expose:
      - 7000
    ports:
      - "127.0.0.1:7000:7000"
    env_file:
      - ./src/.env
    depends_on:
      - db
    networks:
      - evident_network

  db:
    image: postgres:13-alpine
    restart: always
    container_name: evident_postgres
    hostname: evident_postgres
    volumes:
      - ./storage:/var/lib/postgresql/data/
    env_file:
      - ./src/.env
    expose:
      - 5432
    networks:
      - evident_network

volumes:
  static_volume:
  
networks:
  evident_network:
    driver: bridge

Dockerfile

FROM python:3.10.4-slim-bullseye

COPY requirements.txt /requirements.txt

RUN set -ex \
    && BUILD_DEPS=" \  
    apt-utils \
    build-essential \
    ffmpeg libsm6 libxext6 \
    postgresql-client \
    python3-opencv \
    " \
    && apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
    && pip install -U --force-reinstall pip \
    && pip install --no-cache-dir -r /requirements.txt \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir /code/
WORKDIR /code
COPY /src .

EXPOSE 7000

ENTRYPOINT [ "./entrypoint.sh" ]

и ошибки, которые я получаю

evident_django    | django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
evident_django    |     Is the server running on that host and accepting TCP/IP connections?
evident_django    | connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
evident_django    |     Is the server running on that host and accepting TCP/IP connections?
evident_django    | 

Я пробовал менять порты, перезапускать базу данных и не могу понять, почему она не принимает его. Любое руководство было бы очень полезно, я бьюсь уже более 6 часов .

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