I have a PostgreSQL database running on a Windows machine. I'm attempting to connect from a python program running in a docker container to this database using pyodbc. Both database and docker container are running on the same machine.
I use docker compose to define the container:
version: "3.0"
services:
  web:
    image: img-python
    ports:
      - "5000:5000"
      - "5432:5432"
    working_dir: /code
    entrypoint:
      - /pyenv/bin/gunicorn
    command:
      - -b 0.0.0.0:5000
      - --reload
      - app.frontend.app:app
I try to connect like so:
   conn = pyodbc.connect('DRIVER={PostgreSQL ANSI};Server=localhost;Port=5432;
   Database=pydb_0001;UserName=uuuu;Password=pppp;String Types=Unicode')
pyodbc.OperationalError: ('08001', '[08001] could not connect to server: Unknown error\n\tIs the server running on host "localhost" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\n (101) (SQLDriverConnect)')
How to fix the port mapping?
I tried with network_mode: "host" removing the ports and didn't work either.
