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:
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?
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.