Reputation: 345
For the particular image I am trying to run with test containers, it is required to start the container like so after building:
docker run \
-v ~/volume:/tmp/volume\
--cap-add SYS_NICE --cap-add SYS_RESOURCE --cap-add SYS_PTRACE\
docker-image
However i'm wondering how I go about adding the runtime options --cap-add SYS_NICE --cap-add SYS_RESOURCE --cap-add SYS_PTRACE
portion to either the Dockerfile and build my own local copy or use the TestContainer methods or would this even be achieved from configuring the docker daemon? I thought Container.withCommand() did this but seems to overwrite the starting command, not adding these run arguments as far as i am aware.
Upvotes: 6
Views: 2772
Reputation: 171
You can make use of GenericContainer#withCreateContainerCmdModifier(...)
, here is the full example:
new GenericContainer<>(
DOCKER_HOST_CONTAINER_NAME
).withCreateContainerCmdModifier(
it -> it.withHostConfig(
HostConfig.newHostConfig()
.withCapAdd(Capability.NET_ADMIN, Capability.NET_RAW)
.withNetworkMode(network.getId())
)
).withNetwork(network)
.withNetworkAliases(dockerHostName)
.waitingFor(
Wait.forLogMessage(".*Forwarding ports.*", 1)
)
Upvotes: 2