@Test
    public void testElasticsearchCustomMaxHeapSizeInEnvironmentVariable() throws Exception {
        long customHeapSize = 1574961152;

        try (
            ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
                .withEnv("ES_JAVA_OPTS", String.format("-Xms%d  -Xmx%d", customHeapSize, customHeapSize))
        ) {
            container.start();
            assertElasticsearchContainerHasHeapSize(container, customHeapSize);
        }
    }
From 6.8, we can optionally activate security with a default password.
modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java