nicoramirezdev
nicoramirezdev

Reputation: 613

Unable to connect to host from docker container

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:

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?

Upvotes: 1

Views: 1632

Answers (1)

nicoramirezdev
nicoramirezdev

Reputation: 613

My issue was running docker on rootless mode. https://docs.docker.com/engine/security/rootless/

After returning to the default context with

 docker context use default

all the above solutions worked!

Upvotes: 3

Related Questions