Source private docker hub registry credentials from DOCKER_AUTH_CONFIG environment variable
For GitLab CI to use container registries requiring authentication, a common approach is to set the DOCKER_AUTH_CONFIG environment variable. This variable value is the same as that of the contents of ~/.docker/config.json.
Therefore, in GitLab CI today, to use testcontainers one has to write the contents of DOCKER_AUTH_CONFIG to ~/.docker/config.json before running the testcontainers job. For example, here's a GitLab CI job using the example private docker registry at my.private.registry:
build:
stage: build
services:
- name: my.private.registry/docker:dind
alias: docker
variables:
# Instruct Testcontainers to use the daemon of DinD.
DOCKER_HOST: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: my.private.registry/
image: my.private.registry/adoptopenjdk:11-jdk-hotspot
before_script:
- mkdir -p "${HOME}/.docker" && echo "${DOCKER_AUTH_CONFIG}" > "${HOME}/.docker/config.json" # Testcontainers doesn't read the DOCKER_AUTH_CONFIG environment variable, only ~/.docker/config.json
script:
- ./gradlew build
It would be nice for testcontainers to support getting container registry authentication information from DOCKER_AUTH_CONFIG which would make it easier to use with GitLab CI.
I would also like to have support for DOCKER_AUTH_CONFIG. I had to apply same workaroud as @candrews to have testcontainers be able to pull images from private repo when running inside gitlab CI / CD pipeline
it looks like for .net it is already supported, at least according to https://github.com/testcontainers/testcontainers-dotnet/issues/540