Repository navigation
Description
Problem
When porting Particubes' config with @gerhard, we realized that the current docker.#Run implementation doesn't permit the connection with a server running inside a dagger plan, on Windows nor on Mac.
Repro
Given that config:
package main
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: {
_http: docker.#Pull & {
source: "strm/helloworld-http"
}
run: docker.#Run & {
input: _http.image
}
}
}
On Linux, the server is accessible inside your browser at localhost:80. It doesn't work on Mac, neither on Windows.
Context
Normally, we run the buildkitd daemon with the --net=host flag set which should enable this possibility. (cf. https://github.com/dagger/dagger/blob/main/util/buildkitd/buildkitd.go#L183:L191)
However, experience shows it doesn't work on Mac nor Windows
Possible root causes
This seems to be a known issue, and has been asked by docker users for a long time:
- net=host mode bug under mac, container with default bridge mode can not access host opening port docker/for-mac#68
- Block/disallow --net=host (host networking) on Mac OS docker/for-mac#2716
- DOCKER_BUILDKIT=1 prevents custom networks using docker build --network moby/buildkit#978
Also, according to Docker's documentation:
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
More context
From what I understood, this feature is basically not working for these OS. However, when manually exporting ports, the Docker CLI then makes all the necessary networking bindings for it to work.
This is the reason why we did not encounter this issue before, our previous docker.#Run implementation relied on the docker's CLI and we were manually exposing ports. Our current one is just a Buildkit's frontend, we directly write these llb operations:
Previous implementation
registry: docker.#Run & {
ref: "registry:2"
name: "registry-local"
ports: ["5042:5000"]
socket: dockerSocket
}
Which was being run that way:
if [ ! -z "$CONTAINER_PORTS" ]; then
OPTS="$OPTS -p $CONTAINER_PORTS"
fi
docker container run -d $OPTS "$IMAGE_REF"
Potential solution
According to Tonis' message here (moby/buildkit#978 (comment)):
If you want to use custom docker network with buildkit use docker buildx create with --driver-opt network=customname that will create a buildkit instance in docker container that is part of that network. https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md
Buildkit does not depend on libnetwork, and can't see these overlay networks that are internal to docker. Instead deploy Buildkit to the same network with docker to have this behavior.
One possible solution would be to deploy buildkit in a custom docker network, as he states above, and link all #Run to this custom network when running it ?
Activity
dubo-dubon-duponey commentedon Mar 24, 2022
@grouville related: #440
shykes commentedon Apr 8, 2022
It's a coincidence that the port is available on some machines and not others. With the current APIs, it is impossible to reliably expose ports on the local machine. This is because the buildkitd (and the containers it runs) could be anywhere.
The only reliable solution is to proxy inbound ports. See #1258
shykes commentedon Apr 8, 2022
(closing as duplicate)