Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customization of docker.sock path #399

Closed
mniak opened this issue Jan 31, 2022 · 7 comments
Closed

Allow customization of docker.sock path #399

mniak opened this issue Jan 31, 2022 · 7 comments

Comments

@mniak
Copy link
Contributor

mniak commented Jan 31, 2022

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

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.

@austince
Copy link

austince commented Feb 1, 2022

I've seen other examples that suggest using TESTCONTAINERS_RYUK_DISABLED=true, but that doesn't seem to be respected by this lib either, unless I'm mistaken.

@gianarb
Copy link
Collaborator

gianarb commented Feb 3, 2022

Right now we do not implement that but it will be great to cod something that behave like tc-java does
https://www.testcontainers.org/features/configuration/
Thanks for opening this issue and for taking the time

@mniak
Copy link
Contributor Author

mniak commented Feb 21, 2022

PR: #407

@sneko
Copy link

sneko commented Aug 8, 2022

In my case I try to use testcontainers in my CI/CD and to not mess with DinD (docker in docker) I try to use https://github.com/joyrex2001/kubedock (emulating Docker API to create the container on Kubernetes) but for this it requires disabling RYUK (since no real docker available).

As @austince I'm looking for a way to disable Ryuk through TESTCONTAINERS_RYUK_DISABLED=true.

Any fork for this?

Thank you,

EDIT:
I just realised that I can set SkipReaper: true in the testcontainers.ContainerRequest struct so Ryuk is disabled. But that's hardcoded in the code, there is no way to manage it through an environment variable.

I looked a bit more at the code and doing a PR for this is a bit annoying because which would prevail if both are set? Considering TESTCONTAINERS_RYUK_DISABLED for all containers whereas SkipReaper is per request. But since by default SkipReaper is not a pointer it's always considered as false. So to not make breaking change the only solution would be to say, whatever the SkipReaper specified, TESTCONTAINERS_RYUK_DISABLED will override.

In the meantime since my CI/CD had an environment variable CI=true, I set SkipReaper according to it.

@mdelapenya
Copy link
Collaborator

@mniak I think your initial issue with the variable was resolved in #407 and refactored in #414.

@mdelapenya
Copy link
Collaborator

EDIT: I just realised that I can set SkipReaper: true in the testcontainers.ContainerRequest struct so Ryuk is disabled. But that's hardcoded in the code, there is no way to manage it through an environment variable.

I looked a bit more at the code and doing a PR for this is a bit annoying because which would prevail if both are set? Considering TESTCONTAINERS_RYUK_DISABLED for all containers whereas SkipReaper is per request. But since by default SkipReaper is not a pointer it's always considered as false. So to not make breaking change the only solution would be to say, whatever the SkipReaper specified, TESTCONTAINERS_RYUK_DISABLED will override.

In the meantime since my CI/CD had an environment variable CI=true, I set SkipReaper according to it.

@sneko what do you think if we start a discussion on how to redesign this part of the code, supporting a property/env-var to disable Ryuk at the configuration level (probably overridden at the containerRequest level)?

@mdelapenya
Copy link
Collaborator

I moved the settings configuration to a discussion (#531)

I'm closing this issue, as the docker sock path it's now configurable, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants