栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Docker是否构建

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker是否构建

--no-cache
选项将重建图像,而无需使用本地缓存的图层。但是,该
FROM
行将重用已经拉出的基础映像(如果它已存在于构建主机上)(from行本身可能不会被缓存,但是它拉出的映像是已缓存的)。如果要再次拉出基础映像,可以使用
--pull
build命令的选项。例如

$ docker build --no-cache --pull -t new-image-name:latest .

要查看build命令采用的所有选项,可以运行

$ docker build --help

或参阅https://docs.docker.com/engine/reference/commandline/build/上的文档


这是一个示例,您可以自己测试此行为:

$ # very simple Dockerfile$ cat df.testFROM busybox:latestRUN echo hello >test.txt$ # pull an older version of busybox$ docker pull busybox:1.29.21.29.2: Pulling from library/busybox8c5a7da1afbc: Pull completeDigest: sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bdStatus: Downloaded newer image for busybox:1.29.2$ # retag that locally as latest$ docker tag busybox:1.29.2 busybox:latest$ # run the build, note the image id at the end of each build step$ DOCKER_BUILDKIT=0 docker build --no-cache -f df.test .Sending build context to Docker daemon  23.04kBStep 1/2 : FROM busybox:latest ---> e1ddd7948a1cStep 2/2 : RUN echo hello >test.txt ---> Running in dba83fef49f9Removing intermediate container dba83fef49f9 ---> 1f824ff05612Successfully built 1f824ff05612$ # rerun the build, note step 1 keeps the same id and never pulled a new latest$ DOCKER_BUILDKIT=0 docker build --no-cache -f df.test .Sending build context to Docker daemon  23.04kBStep 1/2 : FROM busybox:latest ---> e1ddd7948a1cStep 2/2 : RUN echo hello >test.txt ---> Running in 73df884b0f48Removing intermediate container 73df884b0f48 ---> e5870de6c24fSuccessfully built e5870de6c24f$ # run with --pull and see docker update the latest image, new container id from step 1$ DOCKER_BUILDKIT=0 docker build --no-cache --pull -f df.test .Sending build context to Docker daemon  23.04kBStep 1/2 : FROM busybox:latestlatest: Pulling from library/busyboxDigest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812Status: Downloaded newer image for busybox:latest ---> 59788edf1f3eStep 2/2 : RUN echo hello >test.txt ---> Running in 7204116ecbf4Removing intermediate container 7204116ecbf4 ---> 2c6d8c48661bSuccessfully built 2c6d8c48661b$ # one last run now that busybox:latest is updated shows the pull has nothing to do$ DOCKER_BUILDKIT=0 docker build --no-cache --pull -f df.test .Sending build context to Docker daemon  23.04kBStep 1/2 : FROM busybox:latestlatest: Pulling from library/busyboxDigest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812Status: Image is up to date for busybox:latest ---> 59788edf1f3eStep 2/2 : RUN echo hello >test.txt ---> Running in f37e19024e99Removing intermediate container f37e19024e99 ---> 044a5d4011c4Successfully built 044a5d4011c4


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372406.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号