To use host network in a container one can execute docker run --network=host image
. How can I achieve it using this API?
Asked
Active
Viewed 392 times
0

Okumo
- 169
- 1
- 12
1 Answers
2
I used the following code and it worked for me (Version 8.14.3):
final ContainerConfig containerConfig = ContainerConfig.builder()
.hostConfig(HostConfig.builder().networkMode("host").build())
.image("helloworldjob")
.build();
final ContainerCreation creation = docker.createContainer(containerConfig, "image");
final String id = creation.id();
try {
docker.startContainer(id);
final ContainerExit exit = docker.waitContainer(id);
assertThat(exit.statusCode()).isEqualTo(0);
} finally {
docker.removeContainer(id);
}