testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

[Enhancement]: support Docker contexts

Open ash2k opened this issue 1 year ago • 5 comments

Proposal

Add support for Docker contexts. Currently the code below doesn't look at contexts:

https://github.com/testcontainers/testcontainers-go/blob/e22f2faa2e1accc96b2a00662005fcc17016497d/internal/core/docker_host.go#L99-L124

I'm running Rancher Desktop and the Docker unix socket does not exist at the usual location. Hence, test containers fails to find it. I'm getting an error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?: failed to create container.

My current context is a different one and the socket file is somewhere else:

$ docker context list
NAME                DESCRIPTION                               DOCKER ENDPOINT                      ERROR
default             Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
rancher-desktop *   Rancher Desktop moby context              unix:///Users/mike/.rd/docker.sock

If I set DOCKER_HOST=unix:///Users/mike/.rd/docker.sock, everything works fine. But this shouldn't be necessary.

If this enhancement is implemented, the code should probably print the current context name (for debugging), not just the path to the socket file.

ash2k avatar Jun 26 '24 03:06 ash2k