Skip to content

[Bug]: Different private docker hub registries with supplying through withEnv causing no basic auth error #9959

@wusunny2022

Description

@wusunny2022

Module

Core

Testcontainers version

1.20.4

Using the latest Testcontainers version?

Yes

Host OS

MacOS

Host Arch

ARM

Docker version

27.4.0

What happened?

I want to have different docker private registries setting for my docker compose file. Therefore I am using the approaches that uses placeholder ${DOCKER_REGISTRY_URL} and then supply the value dynamically in the code. The problem is that I got the no basic auth error when trying pull the image from the private registry when running test. I suppose it should be working without problem.

p.s:

  1. I have already docker login in terminal so that I can pull the image from the terminal
  2. Thanks for JapuDCret reply in How to login to private DockerHub registry in runtime? #968 (comment). If the url is hard-coded in the docker-compose file, the image can be pulled and test can be run without problem while on the other hands dynamically url is not working ()

The way I supply in the code (Kotlin)

val redisContainer = DockerComposeContainer(redisConfigFile)
    .withExposedService(
        serviceName,
        servicePort,
        Wait.forListeningPort().withStartupTimeout(Duration.ofMillis(timeout))
    )
    .withEnv("DOCKER_REGISTRY_URL", dockerRegistry)

Example docker compose file

services:
  redis:
    image: ${DOCKER_REGISTRY_URL}/redis:alpine3.20
    ports:
      - 6379
    command: >
      redis-server
      --requirepass password
    networks:
      - test-my-redis-network

networks:
  test-my-redis-network:

Relevant log output

no basic auth credentials

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions