I am having trouble accessing my host machine from a docker container, getting Connection refused error. I tried to solve it following this SO question: From inside of a Docker container, how do I connect to the localhost of the machine?
Docker version is 20.10.18, build b40c2f6 Host is Ubuntu 22.04 LTS
What I am doing:
- Started a server on port 3000 on the host machine
- server is accessible with
curl localhost:3000
Then I tried the following, using curl docker image for testing, all throwing Connection refused error
# using host.docker.internal
docker run --add-host host.docker.internal:host-gateway --rm curlimages/curl:7.85.0 host.docker.internal:3000
# using IP from docker0 network 172.17.0.1
docker run --rm curlimages/curl:7.85.0 172.17.0.1:3000
# using host network
docker run --network=host --rm curlimages/curl:7.85.0 localhost:3000
What am I missing?