Hi,
Some of my containers need to be started with specific --sysctl flags. I don't see any option to pass this values to GenericContainer on creation.
Unfortunately we'd rely on the docker-java library supporting sysctl flags, but based on a quick search of that library's repo and this issue, I think it's not supported yet: docker-java/docker-java#1078.
If we/you/somebody contribute sysctl flag support to docker-java, then it would be easy to use through testcontainers via the withCreateCmdModifier method (since I think it's niche enough that we shouldn't add sysctl support explicitly to the Testcontainers API.
Hi,
I looked at it and... CreateContainerCmd can take HostConfig as one of the parameters. This works for my needs. This is available in 3.1.x version, I tested it with 3.1.0-rc-7.
`
DockerClient dockerClient = DockerClientBuilder.getInstance().build();
HostConfig hc = new HostConfig();
Map<String,String> sysctls = new HashMap<>();
sysctls.put("kernel.msgmnb","1234");
sysctls.put("kernel.msgmni", "123");
sysctls.put("kernel.msgmax", "1234");
ExposedPort tcp1920 = ExposedPort.tcp(1920);
Ports portBindings = new Ports();
portBindings.bind(tcp1920, Ports.Binding.bindPort(1920));
hc.withSysctls(sysctls);
hc.withPortBindings(portBindings);
hc.withPublishAllPorts(true);
CreateContainerResponse container = dockerClient.createContainerCmd("kdappsr")
.withHostConfig(hc).withExposedPorts(tcp1920).exec();
dockerClient.startContainerCmd(container.getId()).exec();
`
I'll check how this will work with testcontainers.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.
This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.
According to the docs from here and in the context of TestContainers, specifying sysctl settings should be possible via withCreateContainerCmdModifier(..):
HostConfig hc = new HostConfig();
Map<String,String> sysctls = new HashMap<>();
sysctls.put("kernel.msgmnb","1234");
sysctls.put("kernel.msgmni", "123");
sysctls.put("kernel.msgmax", "1234");
public GenericContainer container = new GenericContainer<>(DockerImageName.parse("redis:3.0.2"))
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(hostConfig));
@nastra precisely! Thanks for posting an example 馃憤
Most helpful comment
According to the docs from here and in the context of TestContainers, specifying
sysctlsettings should be possible viawithCreateContainerCmdModifier(..):