Skip to content

[Bug]: Elasticsearch: Incorrectly detected OSS image #8849

Open

Description

@OmarHawk

Module

Elasticsearch

Testcontainers version

1.19.8

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host Arch

amd64

Docker version

Client:
 Version:           26.1.0-rd
 API version:       1.44 (downgraded from 1.45)
 Go version:        go1.21.9
 Git commit:        cca8e72
 Built:             Tue Apr 23 16:26:59 2024
 OS/Arch:           windows/amd64
 Context:           default

Server:
 Engine:
  Version:          25.0.5
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       e63daec8672d77ac0b2b5c262ef525c7cf17fd20
  Built:            Sun May 12 07:25:43 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.7.10
  GitCommit:        4e1fe7492b9df85914c389d1f15a3ceedbb280ac
 runc:
  Version:          1.1.12
  GitCommit:        51d5e94601ceffbbd85688df1c928ecccbfa4685
 docker-init:
  Version:          0.19.0
  GitCommit:

What happened?

We are currently trying to use Azure Container registry (ACR) to serve as a pull through cache for Docker images. That one has quite some limitations (e.g.: Azure/acr#599 (comment)), forcing us to configure the Elasticsearch Testcontainer like this (please note the library/ prefix):

            elasticsearchContainer = new ElasticsearchContainer(
                DockerImageName.parse("library/elasticsearch")
                    .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch")
                    .withTag("8.10.4")

            )

This one fails, as it claims it tries to use the OSS version of Elasticsearch while activating a password, even though it is not true (it is not the OSS image...) + I override this anyway with asCompatibleSubstituteFor

Relevant log output

2024-07-05T13:50:43.285Z  INFO 422 --- [dataview] [           main] ContainersSpringContextCustomizerFactory : Warming up the elastic database
2024-07-05T13:50:43.287Z  WARN 422 --- [dataview] [           main] o.t.e.ElasticsearchContainer             : library/elasticsearch is not supported anymore after 7.10.2. Please switch to docker.elastic.co/elasticsearch/elasticsearch
2024-07-05T13:50:43.332Z ERROR 422 --- [dataview] [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.mt.dataview.config.ElasticsearchTestContainer': You can not activate security on Elastic OSS Image. Please switch to the default distribution

Additional Information

Seems like the detection for isOss is could be improved - or maybe removed as it seems marked deprecated anyway...

dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, DEFAULT_OSS_IMAGE_NAME, ELASTICSEARCH_IMAGE_NAME);
if (dockerImageName.isCompatibleWith(DEFAULT_OSS_IMAGE_NAME)) {
this.isOss = true;
log.warn(
"{} is not supported anymore after 7.10.2. Please switch to {}",
dockerImageName.getUnversionedPart(),
DEFAULT_IMAGE_NAME.getUnversionedPart()
);
}

Activity

  1. eddumelendez commented on Jul 5, 2024

    @eddumelendez
    Member

    Hi, I think the code should be

    elasticsearchContainer = new ElasticsearchContainer(
         DockerImageName.parse("myregistry.azurecr.io/docker.io/library/elasticsearch")
            .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch")
            .withTag("8.10.4")
    )
  2. OmarHawk commented on Jul 5, 2024

    @OmarHawk
    Author

    We do have the host name written into
    testcontainers.properties file in our classpath via hub.image.name.prefix property as explained in https://java.testcontainers.org/features/image_name_substitution/

    hub.image.name.prefix=myregistry.azurecr.io/docker.io/
    

    That's why we don't mention it explicitly in our Java code.

  3. OmarHawk commented on Jul 8, 2024

    @OmarHawk
    Author

    Hi, I think the code should be

    elasticsearchContainer = new ElasticsearchContainer(
         DockerImageName.parse("myregistry.azurecr.io/docker.io/library/elasticsearch")
            .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch")
            .withTag("8.10.4")
    )

    Indeed, that did work - explicitly maintaining the registry name as part of the DockerImageName.parse call. I really do wonder why there is a difference between usage of

    hub.image.name.prefix

    and explicitly maintaining it in the Java code. In my opinion they are supposed to be treated equally.

  4. ErickGCA commented on Dec 1, 2026

    @ErickGCA

    found the root cause of this one, it's not elasticsearch specific, DockerImageName.isCompatibleWith builds imageWithLibraryPrefix from this and then compares it back to this instead of other, so any registry-less library/... name is compatible with anything. library/elasticsearch:8.10.4 passes isCompatibleWith(DEFAULT_OSS_IMAGE_NAME), isOss becomes true and withPassword throws, I checked it with a unit test on current main

    that's also why the explicit myregistry.azurecr.io/docker.io/library/elasticsearch worked and hub.image.name.prefix didn't, with a registry in the name the check doesn't match, with the prefix setting the name checked in the constructor is still library/elasticsearch

    #11922 fixes exactly this, with that change the image only matches the elasticsearch default through asCompatibleSubstituteFor, so isOss stays false, might be worth linking it here so both get closed together

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