Skip to content

[Bug]: when a private registry (url/credentials) is specified through System properties, public images cannot be pulled. #6403

@StFS

Description

@StFS

Module

Core

Testcontainers version

1.17.6

Using the latest Testcontainers version?

Yes

Host OS

MacOS / Linux

Host Arch

x86

Docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:01:18 2022
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.14.1 (91661)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:00:19 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

The problem happens for us when we run in our CI environment. The CI job that runs maven integration tests is run inside a fresh container that does not have any docker images cached. We run the maven job and specify a private registry and that seems to result in the public images that are needed (such as ryuk, mysql, kafka and others) not being fetched and erroring with an "invalid username/password" error.

I've managed to reproduce this locally (on a Mac) by following these steps:

  • Make sure your local docker image cache is empty. Running docker images should return an empty list. You can get far at least (maybe even all the way) by running docker system prune -a
  • Make sure that you remove any configuration of your docker setup (move your ~/.docker/config.json file somewhere else) so that you’re basically starting with a clean slate (same as you would be with a clean CI container).
  • With a java project that uses testcontainers with images from a private registry that requires authentication, make sure that registry is not configured to allow passthough proxying of public images from the public docker registry.
  • In that project run: mvn -Dregistry.url=foobar.myregistry.com -Dregistry.username=fluff -Dregistry.password=bunny verify (of course, using the correct url, username and password).
    • This run will fail because it won’t be able to get the public images such as ryuk. You will see a bunch of com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.4: unauthorized: incorrect username or password"}
  • Now, if you try running the maven command again, but not providing the custom registry url/user/pass: mvn verify
    • This run will also fail. The public images will be retrieved but the private ones will not be.
  • Finally, if you run the command one more time, with the private registry url/user/pass, it works because the step above seems to have fetched the public images and stored it in the local docker cache.

Relevant log output

An excerpt from the log output when running the maven command which specifies the private registry:


# We use GitLab which offers a private registry, just a hint if you need to set one up quickly.
# mvn -Dregistry.url=registry.gitlab.com -Dregistry.username=gitlab-token -Dregistry.password=some_very_secure_password verify

...

39665 [main] WARN  🐳 [testcontainers/ryuk:0.3.4]  - Retrying pull for image: testcontainers/ryuk:0.3.4 (81s remaining)
40434 [docker-java-stream--876689195] ERROR com.github.dockerjava.api.async.ResultCallbackTemplate  - Error during callback
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Head \"https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.4\": unauthorized: incorrect username or password"}

	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:247)
	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
	at java.base/java.lang.Thread.run(Thread.java:833)

Note that the error message may change to something like "toomanyrequests" at some point but the first errors should complain about incorrect username/password at least.

Additional Information

I asked about this on the Slack channel and got some good feedback from @kiview . A link to that thread is here: https://testcontainers.slack.com/archives/C1SUBPZK6/p1673350403349039

He points out that this may be something that needs to be fixed in

. It should make sure that the private image registry authentication is only used when fetching images from that registry and when fetching public images it should not be using the auth credentials.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions