Open acouvreur opened 5 months ago
I've tried to allow overriding the context variable, but this is not working properly.
Because in the end, you need to be able to manage multiple instances of one docker client, which is not the case here.
I think this feature would need more than just allowing overriding.
Problem
I'm currently working on Sablier and this project needs to interact with a Docker host. It can list, start and stop containers.
Interacting with direct socket may cause some issues: the workspace is polluted with my containers, and I don't want that.
So I've though of using a Docker in Docker container as my sandbox for my test.
Testcontainers does not enable me to spawn a Docker in Docker container to make subsequent request to it. The current Docker host detection does not allow you to have multiple docker daemon.
Here's my sample:
And I though that Docker host detection rule 3 would actually make the trick.
But it turns out that it does not for multiple reasons:
https://github.com/testcontainers/testcontainers-go/blob/d94455b5799ffe6909eb403dbdba38e2e69fd77a/provider.go#L142
https://github.com/testcontainers/testcontainers-go/blob/d94455b5799ffe6909eb403dbdba38e2e69fd77a/internal/core/docker_host.go#L59-L76
docker_host
is overriden with the one from the providerhttps://github.com/testcontainers/testcontainers-go/blob/d94455b5799ffe6909eb403dbdba38e2e69fd77a/docker.go#L983
Solution
The solution would be to be for testcontainers to be able to pick up multiple containers and fully propagate the docker host at every call.
So that this would be dynamic, it must not be cached.
Benefit
This would allow applications that tests docker interactions to work properly by using testcontainers features.
Alternatives
I could create the Docker in Docker container myself first, but it would defeat the original purpose of testcontainers in my opinion.
Would you like to help contributing this feature?
Yes