testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

[Enhancement]: Provide a method to run container with the --init option

Open veita opened this issue 3 years ago • 3 comments

Module

Core

Proposal

Currently there seems to be no way to pass the --init option to container runs through GenericContainer.

Passing --init can considerably reduce the overall runtime of a container run/stop lifecycle. So having such an option might be beneficial for testcontainers, too.

veita avatar Oct 28 '22 12:10 veita

I am am new to Docker and Testcontainers but I am curious how using the --init option

reduces the overall runtime of a container run/stop lifecycle.

From the reading I have done that option just starts the tini process which is used to manage signals and zombie processes. After tini is started then your process is started.

Thanks.

mdbuck77 avatar Dec 30 '22 14:12 mdbuck77

Isn't the option available through withCreateContainerCmdModifier(Consumer<CreateContainerCmd>)? I think it is part of the HostConfig (withInit(Boolean)).

HofmeisterAn avatar Dec 30 '22 15:12 HofmeisterAn

@mdbuck77

From the reading I have done that option just starts the tini process which is used to manage signals and zombie processes. After tini is started then your process is started.

This is correct. However, there's also container shutdown. E.g. I have experienced a 10 seconds stop delay with a container running ActiveMQ. Similar to the delay you can see when stopping docker.io/rmohr/activemq.

veita avatar Dec 30 '22 15:12 veita

Testcontainers doesn't use the Docker CLI but the Docker API instead. Looking at the stop endpoint there is no init parameter to send. Besides that, Testcontainers uses the Kill Container endpoint.

As mentioned by @HofmeisterAn here, the init can be set

GenericContainer<?> container = new GenericContainer<>("image:tag")
            .withCreateContainerCmdModifier(it -> {
                it
                    .getHostConfig()
                    .withInit(true)
            })

eddumelendez avatar Jul 11 '23 03:07 eddumelendez