Correct options for accessing Docker host IP from inside container
emfax opened this issue · comments
I'm using Bollard to setup a dev environment for testing an ACME client. I need a container that is attached to a custom network to be able to connect to the docker host machine.
There are many ways to determine the docker host IP like,
ip -4 route show default | cut -d" " -f3
or using the host.docker.internal
host name, but any connection is always refused.
I've set privileged: Some(true)
in HostConfig
and various combinations of networking options.
Since bollard makes things fairly specific in what you want to do, I'm thinking I'm missing some options.
This is a help wanted issue, but I can't tag it so I apologise for raising this, but how do I create a container and start it such that I can determine the Docker host ip and connect to it?
(Using Docker desktop Mac 4.21.1 (114176), Docker Engine 24.0.2)
Edit: I should also mention that the container in question can successfully ping hosts on the internet.
Since you're already running in a container, we can assume that this is not about connecting to the main docker host, but this is a docker-in-docker scenario where you're trying to connect to a container running docker itself ?
No, trying to connect to localhost
on the machine running Docker from inside a container. Docker Desktop has the host.docker.internal
host name that resolves to some IP address that will connect to localhost
on the host machine.
This is not a Bollard issue, but a Docker/macOS networking issue.
You can't actually access localhost
on the host machine from a Docker container, at least not on macOS.