|
@@ -213,10 +213,12 @@ public class QuickStart {
|
|
|
DockerClient dockerClient = DockerClientBuilder.getInstance().build();
|
|
DockerClient dockerClient = DockerClientBuilder.getInstance().build();
|
|
|
|
|
|
|
|
// 使用 ping 命令测试连接是否成功
|
|
// 使用 ping 命令测试连接是否成功
|
|
|
|
|
+ // 等价命令: docker version(连接自检,底层请求 HTTP GET /_ping)
|
|
|
dockerClient.pingCmd().exec();
|
|
dockerClient.pingCmd().exec();
|
|
|
log.info("Docker client ping 成功!");
|
|
log.info("Docker client ping 成功!");
|
|
|
|
|
|
|
|
// 列出所有本地镜像,验证连接正常
|
|
// 列出所有本地镜像,验证连接正常
|
|
|
|
|
+ // 等价命令: docker images
|
|
|
dockerClient.listImagesCmd().exec().forEach(image -> {
|
|
dockerClient.listImagesCmd().exec().forEach(image -> {
|
|
|
log.info("Docker 镜像信息: {}", image);
|
|
log.info("Docker 镜像信息: {}", image);
|
|
|
});
|
|
});
|
|
@@ -293,10 +295,12 @@ public class QuickStart {
|
|
|
DockerClient dockerClient = DockerClientImpl.getInstance(dockerClientConfig, httpClient);
|
|
DockerClient dockerClient = DockerClientImpl.getInstance(dockerClientConfig, httpClient);
|
|
|
|
|
|
|
|
// 测试连接
|
|
// 测试连接
|
|
|
|
|
+ // 等价命令: docker version(连接自检)
|
|
|
dockerClient.pingCmd().exec();
|
|
dockerClient.pingCmd().exec();
|
|
|
log.info("自定义配置连接成功!");
|
|
log.info("自定义配置连接成功!");
|
|
|
|
|
|
|
|
// 列出所有镜像
|
|
// 列出所有镜像
|
|
|
|
|
+ // 等价命令: docker images
|
|
|
dockerClient.listImagesCmd().exec().forEach(image -> {
|
|
dockerClient.listImagesCmd().exec().forEach(image -> {
|
|
|
log.info("Docker 镜像信息: {}", image);
|
|
log.info("Docker 镜像信息: {}", image);
|
|
|
});
|
|
});
|
|
@@ -315,6 +319,7 @@ public class QuickStart {
|
|
|
|
|
|
|
|
```java
|
|
```java
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker version(连接自检)
|
|
|
dockerClient.pingCmd().exec();
|
|
dockerClient.pingCmd().exec();
|
|
|
log.info("Docker 连接成功!");
|
|
log.info("Docker 连接成功!");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -326,10 +331,12 @@ try {
|
|
|
|
|
|
|
|
```java
|
|
```java
|
|
|
// 获取 Docker 版本信息
|
|
// 获取 Docker 版本信息
|
|
|
|
|
+// 等价命令: docker version
|
|
|
String version = dockerClient.versionCmd().exec().getVersion();
|
|
String version = dockerClient.versionCmd().exec().getVersion();
|
|
|
log.info("Docker 版本: {}", version);
|
|
log.info("Docker 版本: {}", version);
|
|
|
|
|
|
|
|
// 获取 Docker 系统信息
|
|
// 获取 Docker 系统信息
|
|
|
|
|
+// 等价命令: docker info
|
|
|
Info info = dockerClient.infoCmd().exec();
|
|
Info info = dockerClient.infoCmd().exec();
|
|
|
log.info("Docker 系统信息: {}", info);
|
|
log.info("Docker 系统信息: {}", info);
|
|
|
```
|
|
```
|
|
@@ -350,6 +357,7 @@ import com.github.dockerjava.api.model.PullResponseItem;
|
|
|
public void pullImage(String imageName) {
|
|
public void pullImage(String imageName) {
|
|
|
try {
|
|
try {
|
|
|
// 构建并执行拉取命令
|
|
// 构建并执行拉取命令
|
|
|
|
|
+ // 等价命令: docker pull nginx:latest
|
|
|
// exec() 方法会阻塞直到镜像拉取完成
|
|
// exec() 方法会阻塞直到镜像拉取完成
|
|
|
dockerClient.pullImageCmd(imageName)
|
|
dockerClient.pullImageCmd(imageName)
|
|
|
.exec(new PullImageResultCallback())
|
|
.exec(new PullImageResultCallback())
|
|
@@ -382,6 +390,7 @@ import com.github.dockerjava.api.model.Ports;
|
|
|
public void createAndStartContainer(String imageName, String containerName) {
|
|
public void createAndStartContainer(String imageName, String containerName) {
|
|
|
// 步骤1:创建容器
|
|
// 步骤1:创建容器
|
|
|
// 创建容器只是分配资源和配置,并不会真正运行
|
|
// 创建容器只是分配资源和配置,并不会真正运行
|
|
|
|
|
+ // 等价命令: docker create --name demo-container hello-world
|
|
|
CreateContainerResponse container = dockerClient.createContainerCmd(imageName)
|
|
CreateContainerResponse container = dockerClient.createContainerCmd(imageName)
|
|
|
.withName(containerName) // 设置容器名称
|
|
.withName(containerName) // 设置容器名称
|
|
|
.exec();
|
|
.exec();
|
|
@@ -389,6 +398,8 @@ public void createAndStartContainer(String imageName, String containerName) {
|
|
|
log.info("容器创建成功,ID: {}", container.getId());
|
|
log.info("容器创建成功,ID: {}", container.getId());
|
|
|
|
|
|
|
|
// 步骤2:启动容器
|
|
// 步骤2:启动容器
|
|
|
|
|
+ // 等价命令: docker start demo-container
|
|
|
|
|
+ // 上面两步合起来相当于: docker run --name demo-container hello-world
|
|
|
dockerClient.startContainerCmd(container.getId()).exec();
|
|
dockerClient.startContainerCmd(container.getId()).exec();
|
|
|
log.info("容器 {} 启动成功!", containerName);
|
|
log.info("容器 {} 启动成功!", containerName);
|
|
|
}
|
|
}
|
|
@@ -449,11 +460,13 @@ public class QuickStart {
|
|
|
*/
|
|
*/
|
|
|
public void runDemo() {
|
|
public void runDemo() {
|
|
|
// 1. 测试连接
|
|
// 1. 测试连接
|
|
|
|
|
+ // 等价命令: docker version
|
|
|
dockerClient.pingCmd().exec();
|
|
dockerClient.pingCmd().exec();
|
|
|
log.info("1. Docker 连接成功");
|
|
log.info("1. Docker 连接成功");
|
|
|
|
|
|
|
|
// 2. 拉取 hello-world 镜像
|
|
// 2. 拉取 hello-world 镜像
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker pull nginx:latest
|
|
|
dockerClient.pullImageCmd("hello-world")
|
|
dockerClient.pullImageCmd("hello-world")
|
|
|
.exec(new com.github.dockerjava.api.command.PullImageResultCallback())
|
|
.exec(new com.github.dockerjava.api.command.PullImageResultCallback())
|
|
|
.awaitCompletion();
|
|
.awaitCompletion();
|
|
@@ -465,11 +478,14 @@ public class QuickStart {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 3. 创建并启动容器
|
|
// 3. 创建并启动容器
|
|
|
|
|
+ // 等价命令: docker create --name demo-container hello-world
|
|
|
CreateContainerResponse container = dockerClient.createContainerCmd("hello-world")
|
|
CreateContainerResponse container = dockerClient.createContainerCmd("hello-world")
|
|
|
.withName("demo-container")
|
|
.withName("demo-container")
|
|
|
.exec();
|
|
.exec();
|
|
|
log.info("3. 容器创建成功,ID: {}", container.getId());
|
|
log.info("3. 容器创建成功,ID: {}", container.getId());
|
|
|
|
|
|
|
|
|
|
+ // 等价命令: docker start demo-container
|
|
|
|
|
+ // 上面两步合起来相当于: docker run --name demo-container hello-world
|
|
|
dockerClient.startContainerCmd(container.getId()).exec();
|
|
dockerClient.startContainerCmd(container.getId()).exec();
|
|
|
log.info("4. 容器启动成功");
|
|
log.info("4. 容器启动成功");
|
|
|
}
|
|
}
|
|
@@ -502,6 +518,7 @@ public class QuickStart {
|
|
|
* @return 镜像列表
|
|
* @return 镜像列表
|
|
|
*/
|
|
*/
|
|
|
public List<Image> listImages() {
|
|
public List<Image> listImages() {
|
|
|
|
|
+ // 等价命令: docker images -a(列出所有镜像,包括中间层缩影)
|
|
|
List<Image> images = dockerClient.listImagesCmd()
|
|
List<Image> images = dockerClient.listImagesCmd()
|
|
|
.withShowAll(true) // 展示所有镜像(包括中间层)
|
|
.withShowAll(true) // 展示所有镜像(包括中间层)
|
|
|
.exec();
|
|
.exec();
|
|
@@ -538,6 +555,7 @@ Docker 的镜像采用分层存储架构,一个镜像由多个 Layer 叠加而
|
|
|
* @return 镜像详情
|
|
* @return 镜像详情
|
|
|
*/
|
|
*/
|
|
|
public InspectImageResponse inspectImage(String imageId) {
|
|
public InspectImageResponse inspectImage(String imageId) {
|
|
|
|
|
+ // 等价命令: docker inspect <imageId>
|
|
|
InspectImageResponse response = dockerClient.inspectImageCmd(imageId).exec();
|
|
InspectImageResponse response = dockerClient.inspectImageCmd(imageId).exec();
|
|
|
log.info("镜像 {} 详情: {}", imageId, response);
|
|
log.info("镜像 {} 详情: {}", imageId, response);
|
|
|
return response;
|
|
return response;
|
|
@@ -572,6 +590,7 @@ public InspectImageResponse inspectImage(String imageId) {
|
|
|
*/
|
|
*/
|
|
|
public boolean pullImage(String imageName) {
|
|
public boolean pullImage(String imageName) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker pull ubuntu:latest
|
|
|
// exec() 执行命令,返回异步回调
|
|
// exec() 执行命令,返回异步回调
|
|
|
// awaitCompletion() 阻塞等待镜像拉取完成
|
|
// awaitCompletion() 阻塞等待镜像拉取完成
|
|
|
dockerClient.pullImageCmd(imageName)
|
|
dockerClient.pullImageCmd(imageName)
|
|
@@ -604,6 +623,8 @@ public boolean pullImage(String imageName) {
|
|
|
* @param force 是否强制删除(即使镜像被容器使用)
|
|
* @param force 是否强制删除(即使镜像被容器使用)
|
|
|
*/
|
|
*/
|
|
|
public void removeImage(String imageId, boolean force) {
|
|
public void removeImage(String imageId, boolean force) {
|
|
|
|
|
+ // 等价命令: docker rmi <imageId>
|
|
|
|
|
+ // 等价命令: docker rmi -f <imageId>(force=true 时强制删除)
|
|
|
dockerClient.removeImageCmd(imageId)
|
|
dockerClient.removeImageCmd(imageId)
|
|
|
.withForce(force) // 强制删除
|
|
.withForce(force) // 强制删除
|
|
|
.exec();
|
|
.exec();
|
|
@@ -625,6 +646,7 @@ public void removeImage(String imageId, boolean force) {
|
|
|
* @param tag 新的标签名
|
|
* @param tag 新的标签名
|
|
|
*/
|
|
*/
|
|
|
public void tagImage(String imageId, String repository, String tag) {
|
|
public void tagImage(String imageId, String repository, String tag) {
|
|
|
|
|
+ // 等价命令: docker tag <imageId> <repository>:<tag>
|
|
|
dockerClient.tagImageCmd(imageId, repository, tag).exec();
|
|
dockerClient.tagImageCmd(imageId, repository, tag).exec();
|
|
|
log.info("镜像 {} 已标记为 {}:{}", imageId, repository, tag);
|
|
log.info("镜像 {} 已标记为 {}:{}", imageId, repository, tag);
|
|
|
}
|
|
}
|
|
@@ -644,6 +666,7 @@ Docker 还支持将镜像导出为 tar 文件,或者从 tar 文件导入镜像
|
|
|
// 将镜像导出为 tar 文件
|
|
// 将镜像导出为 tar 文件
|
|
|
public void saveImage(String imageId, String filePath) {
|
|
public void saveImage(String imageId, String filePath) {
|
|
|
try (OutputStream outputStream = new FileOutputStream(filePath)) {
|
|
try (OutputStream outputStream = new FileOutputStream(filePath)) {
|
|
|
|
|
+ // 等价命令: docker save <imageId> -o nginx-backup.tar
|
|
|
dockerClient.saveImageCmd(imageId).exec(outputStream);
|
|
dockerClient.saveImageCmd(imageId).exec(outputStream);
|
|
|
log.info("镜像 {} 已导出到 {}", imageId, filePath);
|
|
log.info("镜像 {} 已导出到 {}", imageId, filePath);
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -654,6 +677,7 @@ public void saveImage(String imageId, String filePath) {
|
|
|
// 从 tar 文件加载镜像
|
|
// 从 tar 文件加载镜像
|
|
|
public void loadImage(String filePath) {
|
|
public void loadImage(String filePath) {
|
|
|
try (InputStream inputStream = new FileInputStream(filePath)) {
|
|
try (InputStream inputStream = new FileInputStream(filePath)) {
|
|
|
|
|
+ // 等价命令: docker load -i nginx-backup.tar
|
|
|
dockerClient.loadImageCmd(inputStream)
|
|
dockerClient.loadImageCmd(inputStream)
|
|
|
.exec(new LoadImageResultCallback())
|
|
.exec(new LoadImageResultCallback())
|
|
|
.awaitCompletion();
|
|
.awaitCompletion();
|
|
@@ -718,6 +742,7 @@ public String buildImage(String dockerfilePath, String imageName) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker build -f Dockerfile -t sdk-demo/hello:latest .
|
|
|
// withDockerfile 指定 Dockerfile 文件位置
|
|
// withDockerfile 指定 Dockerfile 文件位置
|
|
|
// withBaseDirectory 设置构建上下文(当前目录)
|
|
// withBaseDirectory 设置构建上下文(当前目录)
|
|
|
// withTag 指定构建后的镜像名称和标签
|
|
// withTag 指定构建后的镜像名称和标签
|
|
@@ -846,6 +871,7 @@ Docker 的设计哲学是:**创建**和**启动**是分离的操作。创建
|
|
|
*/
|
|
*/
|
|
|
public CreateContainerResponse createContainer(String imageName, String containerName) {
|
|
public CreateContainerResponse createContainer(String imageName, String containerName) {
|
|
|
// 创建容器:分配资源配置,但不会真正运行
|
|
// 创建容器:分配资源配置,但不会真正运行
|
|
|
|
|
+ // 等价命令: docker create --name my-container nginx:latest
|
|
|
// withName 指定容器名称(可选,不指定时 Docker 自动生成)
|
|
// withName 指定容器名称(可选,不指定时 Docker 自动生成)
|
|
|
CreateContainerResponse response = dockerClient.createContainerCmd(imageName)
|
|
CreateContainerResponse response = dockerClient.createContainerCmd(imageName)
|
|
|
.withName(containerName)
|
|
.withName(containerName)
|
|
@@ -871,12 +897,14 @@ public CreateContainerResponse createContainer(String imageName, String containe
|
|
|
|
|
|
|
|
```java
|
|
```java
|
|
|
// 创建带环境变量的容器
|
|
// 创建带环境变量的容器
|
|
|
|
|
+// 等价命令: docker create --name my-container -e MYSQL_ROOT_PASSWORD=123456 nginx:latest
|
|
|
dockerClient.createContainerCmd("nginx:latest")
|
|
dockerClient.createContainerCmd("nginx:latest")
|
|
|
.withName("my-nginx")
|
|
.withName("my-nginx")
|
|
|
.withEnv("NGINX_HOST=localhost", "NGINX_PORT=80")
|
|
.withEnv("NGINX_HOST=localhost", "NGINX_PORT=80")
|
|
|
.exec();
|
|
.exec();
|
|
|
|
|
|
|
|
// 创建带端口映射的容器
|
|
// 创建带端口映射的容器
|
|
|
|
|
+// 等价命令: docker create --name my-container -p 8080:80 nginx:latest
|
|
|
dockerClient.createContainerCmd("nginx:latest")
|
|
dockerClient.createContainerCmd("nginx:latest")
|
|
|
.withName("my-nginx")
|
|
.withName("my-nginx")
|
|
|
.withExposedPorts(ExposedPort.tcp(80))
|
|
.withExposedPorts(ExposedPort.tcp(80))
|
|
@@ -894,6 +922,7 @@ dockerClient.createContainerCmd("nginx:latest")
|
|
|
* @param containerId 容器 ID
|
|
* @param containerId 容器 ID
|
|
|
*/
|
|
*/
|
|
|
public void startContainer(String containerId) {
|
|
public void startContainer(String containerId) {
|
|
|
|
|
+ // 等价命令: docker start <containerId>
|
|
|
dockerClient.startContainerCmd(containerId).exec();
|
|
dockerClient.startContainerCmd(containerId).exec();
|
|
|
log.info("容器 {} 启动成功", containerId);
|
|
log.info("容器 {} 启动成功", containerId);
|
|
|
}
|
|
}
|
|
@@ -914,6 +943,7 @@ public void startContainer(String containerId) {
|
|
|
* @param timeoutSeconds 等待时长(秒),超过则强制终止
|
|
* @param timeoutSeconds 等待时长(秒),超过则强制终止
|
|
|
*/
|
|
*/
|
|
|
public void stopContainer(String containerId, Integer timeoutSeconds) {
|
|
public void stopContainer(String containerId, Integer timeoutSeconds) {
|
|
|
|
|
+ // 等价命令: docker stop -t 10 <containerId>(先发 SIGTERM,超时后 SIGKILL)
|
|
|
dockerClient.stopContainerCmd(containerId)
|
|
dockerClient.stopContainerCmd(containerId)
|
|
|
.withTimeout(timeoutSeconds) // SIGTERM 后等待时间
|
|
.withTimeout(timeoutSeconds) // SIGTERM 后等待时间
|
|
|
.exec();
|
|
.exec();
|
|
@@ -931,6 +961,7 @@ public void stopContainer(String containerId, Integer timeoutSeconds) {
|
|
|
* @param containerId 容器 ID
|
|
* @param containerId 容器 ID
|
|
|
*/
|
|
*/
|
|
|
public void killContainer(String containerId) {
|
|
public void killContainer(String containerId) {
|
|
|
|
|
+ // 等价命令: docker kill <containerId>(立即发送 SIGKILL,不给优雅退出机会)
|
|
|
dockerClient.killContainerCmd(containerId).exec();
|
|
dockerClient.killContainerCmd(containerId).exec();
|
|
|
log.info("容器 {} 已被强制停止", containerId);
|
|
log.info("容器 {} 已被强制停止", containerId);
|
|
|
}
|
|
}
|
|
@@ -952,6 +983,8 @@ public void killContainer(String containerId) {
|
|
|
* @param removeVolumes 是否同时删除关联的卷
|
|
* @param removeVolumes 是否同时删除关联的卷
|
|
|
*/
|
|
*/
|
|
|
public void removeContainer(String containerId, boolean force, boolean removeVolumes) {
|
|
public void removeContainer(String containerId, boolean force, boolean removeVolumes) {
|
|
|
|
|
+ // 等价命令: docker rm <containerId>
|
|
|
|
|
+ // 等价命令: docker rm -f -v <containerId>(同时强制停止并删除数据卷)
|
|
|
dockerClient.removeContainerCmd(containerId)
|
|
dockerClient.removeContainerCmd(containerId)
|
|
|
.withForce(force) // 强制删除运行中的容器
|
|
.withForce(force) // 强制删除运行中的容器
|
|
|
.withRemoveVolumes(removeVolumes) // 删除关联数据卷
|
|
.withRemoveVolumes(removeVolumes) // 删除关联数据卷
|
|
@@ -970,6 +1003,7 @@ public void removeContainer(String containerId, boolean force, boolean removeVol
|
|
|
* @return 容器列表
|
|
* @return 容器列表
|
|
|
*/
|
|
*/
|
|
|
public List<Container> listContainers() {
|
|
public List<Container> listContainers() {
|
|
|
|
|
+ // 等价命令: docker ps -a(列出所有容器,包括已停止的)
|
|
|
// withShowAll(true) 展示所有容器(不只运行中的)
|
|
// withShowAll(true) 展示所有容器(不只运行中的)
|
|
|
List<Container> containers = dockerClient.listContainersCmd()
|
|
List<Container> containers = dockerClient.listContainersCmd()
|
|
|
.withShowAll(true)
|
|
.withShowAll(true)
|
|
@@ -1002,6 +1036,7 @@ public List<Container> listContainers() {
|
|
|
* @return 容器详情
|
|
* @return 容器详情
|
|
|
*/
|
|
*/
|
|
|
public InspectContainerResponse inspectContainer(String containerId) {
|
|
public InspectContainerResponse inspectContainer(String containerId) {
|
|
|
|
|
+ // 等价命令: docker inspect <containerId>(查看容器完整 JSON 详情)
|
|
|
InspectContainerResponse response = dockerClient.inspectContainerCmd(containerId).exec();
|
|
InspectContainerResponse response = dockerClient.inspectContainerCmd(containerId).exec();
|
|
|
log.info("容器 {} 状态: {}, 名称: {}",
|
|
log.info("容器 {} 状态: {}, 名称: {}",
|
|
|
containerId, response.getState().getStatus(), response.getName());
|
|
containerId, response.getState().getStatus(), response.getName());
|
|
@@ -1068,6 +1103,7 @@ Docker 的设计中,一个容器可以有多个名称(别名),通常是
|
|
|
public String getContainerLogs(String containerId, int tailLines) {
|
|
public String getContainerLogs(String containerId, int tailLines) {
|
|
|
StringBuilder logBuilder = new StringBuilder();
|
|
StringBuilder logBuilder = new StringBuilder();
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker logs --tail 10 <containerId>
|
|
|
// withTail 只获取末尾 N 行
|
|
// withTail 只获取末尾 N 行
|
|
|
LogContainerCmd cmd = dockerClient.logContainerCmd(containerId)
|
|
LogContainerCmd cmd = dockerClient.logContainerCmd(containerId)
|
|
|
.withStdOut(true) // 获取标准输出
|
|
.withStdOut(true) // 获取标准输出
|
|
@@ -1126,6 +1162,7 @@ Docker 容器的日志实际上包含两个数据流:标准输出(STDOUT)
|
|
|
public String execCommandInContainer(String containerId, String... command) {
|
|
public String execCommandInContainer(String containerId, String... command) {
|
|
|
StringBuilder output = new StringBuilder();
|
|
StringBuilder output = new StringBuilder();
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker exec <containerId> ls -la /
|
|
|
// 1. 创建 exec 实例(描述要在容器中执行什么命令)
|
|
// 1. 创建 exec 实例(描述要在容器中执行什么命令)
|
|
|
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId)
|
|
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId)
|
|
|
.withCmd(command) // 要执行的命令
|
|
.withCmd(command) // 要执行的命令
|
|
@@ -1170,6 +1207,7 @@ public String execCommandInContainer(String containerId, String... command) {
|
|
|
*/
|
|
*/
|
|
|
public int waitContainer(String containerId, int timeoutSeconds) {
|
|
public int waitContainer(String containerId, int timeoutSeconds) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 等价命令: docker wait <containerId>(阻塞直到容器退出,返回退出码)
|
|
|
WaitContainerResultCallback callback = dockerClient.waitContainerCmd(containerId)
|
|
WaitContainerResultCallback callback = dockerClient.waitContainerCmd(containerId)
|
|
|
.exec(new WaitContainerResultCallback());
|
|
.exec(new WaitContainerResultCallback());
|
|
|
// 阻塞等待容器退出,设置超时
|
|
// 阻塞等待容器退出,设置超时
|
|
@@ -1207,6 +1245,7 @@ public void opsDemo() {
|
|
|
log.info("3. 容器日志:\n{}", logs);
|
|
log.info("3. 容器日志:\n{}", logs);
|
|
|
|
|
|
|
|
// 4. 清理容器
|
|
// 4. 清理容器
|
|
|
|
|
+ // 等价命令: docker rm -f <containerId>(测试清理用)
|
|
|
dockerClient.removeContainerCmd(id).withForce(true).exec();
|
|
dockerClient.removeContainerCmd(id).withForce(true).exec();
|
|
|
log.info("4. 临时容器已清理");
|
|
log.info("4. 临时容器已清理");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|