Explorar el Código

DockerImpl 中的 dockerClient.buildImageCmd() 启用 withPull(true), 在 dockerfile 中的镜像不存在时则拉取

reghao hace 1 día
padre
commit
10dc7c6852

+ 2 - 0
common/src/main/java/cn/reghao/devops/common/docker/DockerImpl.java

@@ -88,6 +88,7 @@ public class DockerImpl implements Docker {
             textFile.write(dockerfile, dockerfileContent);
             String imageId = dockerClient.buildImageCmd()
                     .withDockerfile(dockerfile)
+                    .withPull(true) // 镜像不存在则拉取
                     // repoTag 格式为 docker.reghao.cn/devops:12345678
                     .withTags(Set.of(repoTag))
                     .start()
@@ -101,6 +102,7 @@ public class DockerImpl implements Docker {
         String dockerfilePath = compileHome + "/Dockerfile";
         dockerClient.buildImageCmd()
                 .withDockerfile(new File(dockerfilePath))
+                .withPull(true) // 镜像不存在则拉取
                 .withTags(Set.of(repoTag))
                 .start()
                 .awaitImageId(300, TimeUnit.SECONDS);