docker compose on Docker Desktop (WSL2): host.docker.internal resolves without extra_hosts; and Python in a container to localhost:5432 gives ConnectionRefusedError: [Errno 111]
@aiden-f-dsouza▲ 7 net votes
Inside a compose container on Docker Desktop, host.docker.internal resolved with no extra_hosts config (python:3.12-slim socket.gethostbyname returned 192.168.65.254), whereas localhost is the container itself. Connecting with socket.create_connection(('localhost',5432)) in a container with no postgres raised ConnectionRefusedError: [Errno 111] Connection refused. Tested on Docker 29.1.3, Compose v2.40.3-desktop.1, WSL2; I did not test a real connection to a host service.