-
-
Notifications
You must be signed in to change notification settings - Fork 601
Allow customization of docker.sock path #399
Description
Feature Request
I would like that the library understands an envbironment variable TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE and uses this when starting the reaper container (ryuk)
I'll try to contribute some code when I have some spare time
Something like this (using pseudo code on the change section):
on
Lines 58 to 69 in 9c3076f
| req := ContainerRequest{ | |
| Image: reaperImage(reaperImageName), | |
| ExposedPorts: []string{string(listeningPort)}, | |
| Labels: map[string]string{ | |
| TestcontainerLabel: "true", | |
| TestcontainerLabelIsReaper: "true", | |
| }, | |
| SkipReaper: true, | |
| Mounts: Mounts(BindMount("/var/run/docker.sock", "/var/run/docker.sock")), | |
| AutoRemove: true, | |
| WaitingFor: wait.ForListeningPort(listeningPort), | |
| } |
req := ContainerRequest{
Image: reaperImage(reaperImageName),
ExposedPorts: []string{string(listeningPort)},
Labels: map[string]string{
TestcontainerLabel: "true",
TestcontainerLabelIsReaper: "true",
},
SkipReaper: true,
// THIS ->
Mounts: Mounts(BindMount(
strings.Coalesce(os.GetEnv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE"), "/var/run/docker.sock"),
"/var/run/docker.sock",
)),
// <- THIS
AutoRemove: true,
WaitingFor: wait.ForListeningPort(listeningPort),
}Motivation
Context
Following the announcement that Docker Desktop is not free anymore some users started using different tools to manage and their containers.
In some workaround scenarios the socket docker.sock is created in non-standard locations.
It's easy to setup the DOCKER_HOST environment variable and most applications that use the Docker API will run just fine.
But in testcontainers-go the reaper container, ryuk is set-up to use the standard location.
Some tutorials [#1], [#2] suggest setting up the environment variable TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE, but according to my research, only testcontainers-java and testcontainers-node make use of these variables.
Example
Mac users, for instance, can use lima-vm/lima and install docker inside a virtual machine.
Most tutorials and sample config files create the socket on /run/user/502/docker.sock on the guest vm and a symlink at $HOME/docker.sock on the host computer.