Original title: Python in a Docker Container refused connection to Postgres in a networked Docker Container

I am trying to connect from a python script to a postgres database. Here’s my docker-compose: networks: backend: name: value_tracker_backend external: true services: db: build: context: ./sql dockerfile: db.dockerfile environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: EntitiesAndValues ports: - “5431:5432” healthcheck: test: [“CMD-SHELL”, “pg_isready -U postgres -d EntitiesAndValues”] interval: 10s retries: 5 start_period: 30s timeout: 10s networks: - backend dataseeder: build: context: . dockerfile: dataseeder/dataseeder.dockerfile depends_on: db: condition: service_healthy restart: true networks: - backend

And here’s a snippet of the python code that’s attempting to connect via dockers internal network: import psycopg2 from enum import Enum

class DatabaseConnector: def init(self, db_name, db_user): self.db_name

Read the original question here