4

I am trying to programmatically create and spin up a Testcontainers GenericContainer from a docker image hosted in a private AWS ECR repository. This will be used for automated integration tests, will be run locally and within CICD pipelines. I know I need to authenticate to pull down the image but it is not clear to me how best to get and pass authentication information from AWS to the Testcontainers context. I've read over the Testcontainers documentation but have not found details on how to authenticate to a private docker container repository.

Code I have so far is:

import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName

const val imageName = "<account>.dkr.ecr.<region>.amazonaws.com/<imageName>:<version>"
val testContainer = GenericContainer(DockerImageName.parse(imageName))
testContainer.start()

Of course, this gives an error:

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)
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Head \"https://<account>.dkr.ecr.<region>.amazonaws.com/v2/<imageName>/manifests/<version>\": no basic auth credentials"}

So far I have found Testcontainers to be intuitive to use for all things, but this problem has got me stumped. How does one use Testcontainers with private AWS ECR repositories?

  • This [issue on GitHub](https://github.com/testcontainers/testcontainers-java/issues/1689) didn't provide any help? What have you tried so far to pass the ECR credentials? – rieckpil Feb 20 '22 at 07:50
  • I've been searching for the exact same answer. Looking into LocalStack now... – rmpt Feb 21 '22 at 17:43
  • I've stumbled upon the same issue, have you happened to find a solution for that? – Mark Bramnik Oct 18 '22 at 07:37
  • @MarkBramnik I ended up using a GitHub action to pull the docker image for the CICD pipelines, so it was found local when running the testing suite. And for running local I had to pull the image in advance with AWS cli. So, in short, not really, but did find a workaround. – Jeff Trimmer Oct 21 '22 at 20:52

0 Answers0