[英]docker-java run container with -rm flag
I am using docker-java to spawn new containers.我正在使用docker-java来生成新容器。 I want to remove the containers after they are finished.
我想在完成后移除容器。 Is there a way to achieve this with docker-java?
有没有办法用 docker-java 来实现这一点?
So I basically want something like所以我基本上想要类似的东西
docker run --rm my-docker
with docker-java.使用 docker-java。
In the Docker HTTP API , the docker run --rm
option translates to an AutoRemove
option inside a HostConfig
object.在Docker HTTP API 中,
docker run --rm
选项转换为HostConfig
对象内的AutoRemove
选项。 The Java API mirrors this object layout. Java API 反映了此对象布局。 The
docker-java
wiki doesn't have any good examples of using that object, but it's in the Java API too . docker-java
wiki没有任何使用该对象的好例子,但它也在 Java API 中。
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.model.HostConfig;
HostConfig hostConfig = HostConfig
.newHostConfig()
.withAutoRemove(true); // Set the "remove" flag
CreateContainerResponse container = dockerClient
.createContainerCommand("busybox")
.withHostConfig(hostConfig) // Add in the HostConfig object
.exec();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.