testcontainers / testcontainers/testcontainers-java

TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX doesn't affect image location when using ImageFromDockerfile

Open
#3,688 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Hi. I found that when I set env TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=myrepo.com/ not all images are downloaded from our internal repository. In code we are having:

    ImageFromDockerfile().withDockerfileFromBuilder {
        it.from("consul:latest")
        ....
    })

FromStatementTrait doesn't use ImageNameSubstitutor what cause that docker pull image from dockerhub.

I've made a fix https://github.com/lukidzi/testcontainers-java/tree/fix-missing-prefix, but one test doesn't pass. It is caused by specific image scratch. My change introduce .asCanonicalNameString() and that caused image path change from scratch to scratch:latest what cause the problem. I can prepare a pull request but I am not sure how to fix this specific test. It looks like some problem with not handling tag by docker-java?. https://github.com/lukidzi/testcontainers-java/blob/fix-missing-prefix/core/src/test/java/org/testcontainers/images/builder/ImageFromDockerfileTest.java

FROM scratch:latest

15:47:06.784 INFO  org.testcontainers.images.builder.ImageFromDockerfile - Transferred 20 bytes to Docker daemon
15:47:06.855 ERROR 🐳 [localhost/testcontainers/8wafezi9leafaish] - 'scratch' is a reserved name

Could not build image: 'scratch' is a reserved name
com.github.dockerjava.api.exception.DockerClientException: Could not build image: 'scratch' is a reserved name
	at com.github.dockerjava.api.command.BuildImageResultCallback.getImageId(BuildImageResultCallback.java:78)
	at com.github.dockerjava.api.command.BuildImageResultCallback.awaitImageId(BuildImageResultCallback.java:50)
	at org.testcontainers.images.builder.ImageFromDockerfile.resolve(ImageFromDockerfile.java:141)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with FromStatementTrait and ImageFromDockerfile, then run core/src/test/java/org/testcontainers/images/builder/ImageFromDockerfileTest.java to reproduce the prefix behavior and the scratch failure. Done means Dockerfile base images use the configured image prefix without changing the reserved scratch image semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java
Domain
devops, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.