Skip to content

ImageFromDockerfile.withDockerfileFromBuilder not possible to use with proxy #5103

Description

@nylund

Please provide a way to allow customization of an image when pulling it through a proxy. For example this snippet does not work if ELASTICSEARCH_IMAGE uses an in-house/local docker proxy:

ImageFromDockerfile customImage = new ImageFromDockerfile()
    .withDockerfileFromBuilder(builder ->
        builder
        .from(ELASTICSEARCH_IMAGE)
        .run("bin/elasticsearch-plugin", "install", "analysis-kuromoji")
        .build());

Ends up in exception:

java.lang.IllegalStateException: Failed to verify that image 'localhost/testcontainers/shreetkrpuzjpwzg' is a compatible substitute for 'docker.elastic.co/elasticsearch/elasticsearch'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("localhost/testcontainers/shreetkrpuzjpwzg").asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");
and then use `myImage` instead.

Is there a way to turn off this type of validation?

Version: 1.16.3

Activity

  1. kiview commented on Feb 21, 2022

    @kiview
    Member

    Did you try the code as provided by the exception message?

    DockerImageName myImage = DockerImageName.parse("localhost/testcontainers/shreetkrpuzjpwzg")
      .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");

    This exception happens when you start the Elasticsearch container, it has nothing to do with pulling through a proxy.

  2. nylund commented on Feb 21, 2022

    @nylund
    Author

    I did that for another case but I cannot wrestle the API to use DockerImageName instances in this case. The builder.from() method only takes a String.

  3. nylund commented on Feb 21, 2022

    @nylund
    Author

    And note that 'localhost/testcontainers/shreetkrpuzjpwzg' is not a name from our code but that seems to be auto generated by something inside TestContainers. ELASTICSEARCH_IMAGE is in our case set to "in-house-proxy/elasticsearch/elasticsearch:6.8.8".

  4. kiview commented on Feb 21, 2022

    @kiview
    Member

    Can you try something along the lines of:

    DockerImageName myImage = DockerImageName.parse(customImage.resolve())
      .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");
  5. nylund commented on Feb 21, 2022

    @nylund
    Author

    resolve() is protected so I can't call that one.

  6. bsideup commented on Feb 21, 2022

    @bsideup
    Member

    .get() is the method

  7. nylund commented on Feb 21, 2022

    @nylund
    Author

    Great, this works! Thanks so much for the fast feedback.

    FYI - I am asking around internally if our company can become sponsors for Testcontainers. No promises but I'll see what I can do.

  8. kiview commented on Feb 21, 2022

    @kiview
    Member

    Great we could solve it for your use case 🙂
    I will try to close and convert this issue into a GitHub Discussion question, let's see if this works as expected.

    Also, we really appreciate advocating for Testconainers in your organization and helping others adopt it for their integration testing needs.

  9. locked and limited conversation to collaborators on Feb 21, 2022
  10. converted this issue into a discussion #5104 on Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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