How to configure docker/docker-compose to use Nexus by default instead of docker.io?

Viewed 1552

I'm trying to use TestContainers to run JUnit tests. However, I'm getting a InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/: Forbidden"} error.

Please note, that I am on a secure network.

I can replicate this by doing docker pull testcontainers/ryuk on the command line.

$ docker pull testcontainers/ryuk
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: Forbidden

However, I need it to pull from our nexus service: https://nexus.company.com/18443. Inside the docker-compose file, I'm already using the correct nexus image path. (Verified by manually starting it with docker-compose. However TestContainers also pulls in additional images which are outside the docker-compose file. It is these images that are causing the failure.

I'd be glad for either a Docker Desktop or TestContainers configuration change that would fix this for me.

Note: I've already tried adding the host URL for nexus to the Docker Engine JSON configuration on the dashboard, with no change to the resulting error when doing docker pull.

2 Answers

Since the version 1.15.1 Testcontainers allow to automatically append prefixes to all docker images. In case your private registry is configured as a docker hub mirror this functionality should help with the mentioned issue.

Quote from the documentation:

You can then configure Testcontainers to apply the prefix registry.mycompany.com/mirror/ to every image that it tries to pull from Docker Hub. This can be done in one of two ways:

  • Setting environment variables TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/
  • Via config file, setting hub.image.name.prefix in either:
    • the ~/.testcontainers.properties file in your user home directory, or
    • a file named testcontainers.properties on the classpath

Basically set the same prefix you did for the images in your docker-compose file.

If you're stuck with older versions for some reason, a deprecated solution would be to override just the ryuk.container.image property. Read about it here.

The process is described on this page:

Add the following to your Docker daemon config:

{
  "registry-mirrors": ["https://nexus.company.com:18443"]
}

Make sure to restart the daemon to apply the changes.

Related