Open sbrajchuk opened 1 year ago
You cannot resolve
host.docker.internal
while building with a custom builder
Not sure what's your use case here. Do you want to connect to a service on the host?
Yes, I need to connect to a service on the host, and it is possible, but only by using its IP address. Additionally, if I need to connect to another container that was started in the test network, it is also only possible by using its IP address.
I'm using Testcontainers. Application tests are initiated during the Dockerfile build process, and they require access to both the host and the container inside the build network, which I'm using to interact with Docker on the host. I relocated this container to a separate network to restrict access to Docker on the host from other containers.
Same here. When I try to access a custom docker network from a container started within docker:24.0.6-dind, I have to export DOCKER_BUILDKIT=0
to use the deprecated builder, otherwise the (host-)names of the containers in the custom docker network would not be resolved. I have a setup similar to @sbrajchuk wanting to fetch software from a repository provided by a container in the custom network.
build command inside the dind container is
docker build . -t my_fancy_new_container -f Containerfile --network=host
Same here, using Docker version 25.0.3 and BuildKit version 0.15.2.
If I'm understanding correctly, any Docker container belonging to a network forwards DNS requests to the Docker daemon. To do that, Docker replaces the default /etc/resolv.conf
with custom configuration.
$ docker run -it --rm alpine cat /etc/resolv.conf
# DNS requests are forwarded to the host. DHCP DNS options are ignored.
nameserver 192.168.65.7
$ docker network create test-network
$ docker run -it --rm --network test-network alpine cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
Instead, builder containers, even when created with the option --driver-opt network=<network>
, don't seem to be forwarding DNS request to the Docker daemon, apparently relying on hardcoded configuration only (Google DNS).
options ndots:0
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
For this reason, builder containers are unable to resolve any Docker host name, like host.docker.internal
, or any other container host name in the same network.
Contributing guidelines
I've found a bug and checked that ...
Description
You cannot resolve
host.docker.internal
while building with a custom builder that has been created with--driver-opt network=custom-net
.Expected behaviour
The
host.docker.internal
can be successfully resolved.Actual behaviour
The resolution of
host.docker.internal
is not successful.Buildx version
github.com/docker/buildx v0.11.2-desktop.4 b9955a86a20bf0112ebb4f14424bf59fc46ee179
Docker info
Builders list
Configuration
Build logs
Additional info
When
DOCKER_BUILDKIT
is set to 0, runningdocker build --network=test-net .
performs as expected, although a deprecation warning is displayed.