@Test
    public void testElasticsearch8SecureByDefaultHttpWaitStrategy() throws Exception {
        final HttpWaitStrategy httpsWaitStrategy = Wait
            .forHttps("/")
            .forPort(9200)
            .forStatusCode(200)
            .withBasicCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)
            // trusting self-signed certificate
            .allowInsecure();

        try (
            ElasticsearchContainer container = new ElasticsearchContainer(
                "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"
            )
                .waitingFor(httpsWaitStrategy)
        ) {
            // Start the container. This step might take some time...
            container.start();

            assertClusterHealthResponse(container);
        }
    }
From 6.8, we can optionally activate security with a default password.
modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java