To use host network in a container one can execute docker run --network=host image
. How can I achieve it using this API?
问问题
321 次
1 回答
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);
}
于 2019-05-24T14:55:43.937 回答