使用buildah命令构建图像时使用缓存层
我是容器化环境的新手,并且开始使用Buildah工具构建容器图像,但是在创建图像时很难理解高速缓存层。有人可以帮我澄清吗?
我使用简单的Docker文件构建图像为:
FROM docker.io/library/alpine as downloader
USER root
RUN touch /tmp/hello.txt
FROM docker.io/library/fedora
ENV foo=bar
RUN mkdir blah
COPY --from=downloader /tmp/hello.txt /blah/
我尝试使用的第一个 - 层选项,将使用缓存而不是构建新的:
cmd: buildah bud --layers -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
--> Using cache 532252175243c24d52fdd0ee508d8e37ca64082e3547d531773ea195df567201
STEP 3: RUN touch /tmp/hello.txt
--> Using cache 40811fe6bc8e50fca9287bdbd841259dc1536a7bfbcd5bcf22935acfc88752a0
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
--> Using cache b364a92d2918c2967072154500df94410c04a41cdfd080409afcb344eb331c88
STEP 6: RUN mkdir blah
--> Using cache e095949ceaf95f93dfa874b1919ae3e0571cc800c5740a779623f5f5e8d63b6c
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
--> Using cache 57ec2b918030cf2819de3277c6c56d3f3031eaa0a777d1bc530730797a6a0098
第二,我尝试使用-no-cache选项:
cmd: buildah bud --no-cache -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
STEP 3: RUN touch /tmp/hello.txt
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
STEP 6: RUN mkdir blah
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
STEP 8: COMMIT
0c6ef582c048279a07d22853e150acfa86204785a0428c42c1d86727a37ccb35
==> 最终, buildah工具会自动生成“缓存”
,我尝试了 - 层和 - no-cache选项:
cmd: buildah bud -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
STEP 3: RUN touch /tmp/hello.txt
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
STEP 6: RUN mkdir blah
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
STEP 8: COMMIT
Getting image source signatures
Copying blob 811f92a7a340 skipped: already exists
Copying blob 5ad2f740e5d2 done
Copying config 1c0fa8762d done
Writing manifest to image destination
Storing signatures
1c0fa8762d23aa73a4a9d54d33c4527d91bee51cf7c202d9922a70a6dd889a13
==>没有使用缓存,并且不使用提交步骤会自动生成,但是使用更多日志,
我无法区分 - no-cache,而没有-no-cache选项,而当不存在-no-cache选项时不是重复使用缓存吗? 还有一个问题,为什么不包括Dockerfile,为什么要出现提交步骤?
I'm a newbie to the containerization environment and I'm starting to build container images with buildah tool but it's hard to understand the cache layer while creating images. Could someone help me clarify?
I build images with simple docker file as:
FROM docker.io/library/alpine as downloader
USER root
RUN touch /tmp/hello.txt
FROM docker.io/library/fedora
ENV foo=bar
RUN mkdir blah
COPY --from=downloader /tmp/hello.txt /blah/
The first one i try to with --layers option, Caching will be used instead of building new:
cmd: buildah bud --layers -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
--> Using cache 532252175243c24d52fdd0ee508d8e37ca64082e3547d531773ea195df567201
STEP 3: RUN touch /tmp/hello.txt
--> Using cache 40811fe6bc8e50fca9287bdbd841259dc1536a7bfbcd5bcf22935acfc88752a0
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
--> Using cache b364a92d2918c2967072154500df94410c04a41cdfd080409afcb344eb331c88
STEP 6: RUN mkdir blah
--> Using cache e095949ceaf95f93dfa874b1919ae3e0571cc800c5740a779623f5f5e8d63b6c
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
--> Using cache 57ec2b918030cf2819de3277c6c56d3f3031eaa0a777d1bc530730797a6a0098
Second, I try with --no-cache option:
cmd: buildah bud --no-cache -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
STEP 3: RUN touch /tmp/hello.txt
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
STEP 6: RUN mkdir blah
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
STEP 8: COMMIT
0c6ef582c048279a07d22853e150acfa86204785a0428c42c1d86727a37ccb35
==> Cache is not used and the COMMIT step is generated automatically by buildah tool
Finally, I tried without --layers and --no-cache options:
cmd: buildah bud -f Dockerfile .
STEP 1: FROM docker.io/library/alpine AS downloader
STEP 2: USER root
STEP 3: RUN touch /tmp/hello.txt
STEP 4: FROM docker.io/library/fedora
STEP 5: ENV foo=bar
STEP 6: RUN mkdir blah
STEP 7: COPY --from=downloader /tmp/hello.txt /blah/
STEP 8: COMMIT
Getting image source signatures
Copying blob 811f92a7a340 skipped: already exists
Copying blob 5ad2f740e5d2 done
Copying config 1c0fa8762d done
Writing manifest to image destination
Storing signatures
1c0fa8762d23aa73a4a9d54d33c4527d91bee51cf7c202d9922a70a6dd889a13
==> Cache is not used and the COMMIT step is generated automatically but with more logs
I can not distinguish between the --no-cache and without the --no-cache option, and when the --no-cache option is not present why it is not re-use cache?
One more question, why does the COMMIT step appear although the Dockerfile is not included?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论