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

Feature: Docker private registry support

Open claussa opened this issue 9 months ago • 14 comments

What are you trying to do?

I want to use testcontainers with an image store on a private registry. Correct me if I am wrong, It is currently not possible on testcontainers-python but it is possible on testcontainers-java.

Why should it be done this way?

Example on how it is done on testcontainers-java: https://github.com/testcontainers/testcontainers-java/blob/994b385761dde7d832ab7b6c10bc62747fe4b340/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java#L37

claussa avatar May 06 '24 14:05 claussa

thank you for the example - before reading that code, i never understood what this meant - i suppose in ci environments you have to get creative on how to pull your images, so that makes sense. if i understand correctly, this is just passing an auth parameter for pulling an image if it doesnt exist (and workaround is then just to pull the image ahead of time?)

alexanderankin avatar May 07 '24 13:05 alexanderankin

  1. Will this need support for more than one auth server? or basic support is for a single config? the basic example is :
{
    "auths": {
        "registry.example.com:5000": {
            "auth": "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="
        }
    }
}

note the plural auths :)

  1. I assume this does not include ~/.docker/config.json as its another feat all by itself right?

Tranquility2 avatar May 07 '24 21:05 Tranquility2

Good news. I think I got it working for a single registry:

 echo "$DOCKER_AUTH_CONFIG"
{
        "auths": {
                "localhost:5000": {
                        "auth": "..."
                }
        },
}

>>> from testcontainers.redis import RedisContainer
>>> with RedisContainer() as redis_container:
...     redis_client = redis_container.get_client()
...
Pulling image testcontainers/ryuk:0.7.0
Container started: bb76132ce865
Waiting for container <Container: bb76132ce865> with image testcontainers/ryuk:0.7.0 to be ready ...
Pulling image localhost:5000/redis:latest
Container started: a48fd2609171
Waiting for container <Container: a48fd2609171> with image localhost:5000/redis:latest to be ready ...
Waiting for container <Container: a48fd2609171> with image localhost:5000/redis:latest to be ready ...
Waiting for container <Container: a48fd2609171> with image localhost:5000/redis:latest to be ready ...

Tranquility2 avatar May 07 '24 22:05 Tranquility2

is there a PR to look at or is that just bulit-in functionality from docker-py?

alexanderankin avatar May 08 '24 06:05 alexanderankin

I have the code (I tried to keep it to something very minimal), not a built in as docker-py only supports simple login and you need to pass all the params (feel free to correct me if I missed something), so needed to unpack and decode the data. In any case I need to prepare it for a PR, please tell me if my assumptions on https://github.com/testcontainers/testcontainers-python/issues/562#issuecomment-2099376599 are correct so I'll know how to proceed. Do we assume you only want to work with the private registry if the env var is available? if thats not the case the code needs to be a bit more complicated and on each Container run (docker pull) we will need to check the prefix of the image tag and login to the specific server.

Tranquility2 avatar May 08 '24 07:05 Tranquility2

Feel free to assign me :)

Tranquility2 avatar May 15 '24 08:05 Tranquility2