Skip to content

docker.#Run doesn't expose ports to host on Windows and Mac #1844

Closed

Description

@grouville

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:

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.

(cf. https://docs.docker.com/network/host/)

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"

(cf. https://github.com/dagger/dagger/blob/fa41177e1a2e3500c20f35ffd756988c6993c1e8/pkg/alpha.dagger.io/docker/docker.cue#L249:L253)

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 ?

cc @aluzzardi @gerhard

Activity

  1. dubo-dubon-duponey commented on Mar 24, 2022

    @dubo-dubon-duponey
    Contributor

    @grouville related: #440

  2. shykes commented on Apr 8, 2022

    @shykes
    Contributor

    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

  3. shykes commented on Apr 8, 2022

    @shykes
    Contributor

    (closing as duplicate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions