[Enhancement]: Provide a method to run container with the --init option
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.
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.
Isn't the option available through withCreateContainerCmdModifier(Consumer<CreateContainerCmd>)? I think it is part of the HostConfig (withInit(Boolean)).
@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.
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)
})