@Test
    public void testElasticsearch8SecureByDefaultFailsSilentlyOnLatestImages() throws Exception {
        // this test exists for custom images by users that use the `latest` tag
        // even though the version might be older than version 8
        // this tags an old 7.x version as :latest
        tagImage("docker.elastic.co/elasticsearch/elasticsearch:7.9.2", "elasticsearch-tc-older-release", "latest");
        DockerImageName image = DockerImageName
            .parse("elasticsearch-tc-older-release:latest")
            .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");

        try (ElasticsearchContainer container = new ElasticsearchContainer(image)) {
            container.start();

            Response response = getClient(container).performRequest(new Request("GET", "/_cluster/health"));
            assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
            assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");
        }
    }
From 6.8, we can optionally activate security with a default password.
modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java