gpt4 book ai didi

docker - Dockerfile:通过RUN对文件系统所做的更改不会持久

转载 作者:行者123 更新时间:2023-12-02 19:21:48 24 4
gpt4 key购买 nike

我无法通过网络搜索site:stackoverflow.com dockerfile RUN fs changes not persisted来找到这种特殊之处。

我做了Dockerfile并想通过RUN在图像中进行一些更改。首先,我想更改文件属性,但是启动容器中没有更改。我发现这篇文章涉及dockerchmod错误和解决方法:https://serverfault.com/questions/772227/chmod-not-working-correctly-in-docker。但是,现在我只是尝试通过RUN touch /path/file中的Dockerfile创建一个文件,并且已经在下一个命令(据我所知,文档为docker的下一层)上的更改(该文件)消失了。据我所知,奇怪的是,否则apt install会如何工作,因为它将更改镜像中的文件系统...为什么该特定RUN的结果不持久?下面的文档说的相反(或者我在这里误解了commit的含义):

https://docs.docker.com/engine/reference/builder/:

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.



这是 docker build --no-cache -t yandex:user5 yandex2/的输出(请参阅步骤6和7;已创建dockeruser,顺便说一句):
Step 1/8 : FROM artifactory.dev.foo.org:5000/yandex-tank:jmeter
---> b8286a9220ca
Step 2/8 : LABEL maintainer="foo@foo.org"
---> Running in 7cfde9a90bf2
Removing intermediate container 7cfde9a90bf2
---> b5acd9d55f9c
Step 3/8 : WORKDIR /var/loadteest
---> Running in 47e9adc401bb
Removing intermediate container 47e9adc401bb
---> 103f158e0be3
Step 4/8 : USER root
---> Running in 9923d71f7b08
Removing intermediate container 9923d71f7b08
---> bb3aa8672bc6
Step 5/8 : RUN groupadd -r dockeruser && useradd -r -g dockeruser -d /var/loadtest -s /sbin/nologin -c "Docker image user" dockeruser
---> Running in 48c89f33d750
Removing intermediate container 48c89f33d750
---> 5000afa7698d
Step 6/8 : RUN touch /var/loadtest/chmodtest.txt
---> Running in 00b2d1ccad75
Removing intermediate container 00b2d1ccad75
---> c35808f13344
Step 7/8 : RUN ls -al /var/loadtest
---> Running in cc08d129eeb3
total 8
drwxr-xr-x 2 root root 4096 Nov 20 12:19 .
drwxr-xr-x 1 root root 4096 Nov 29 06:15 ..
Removing intermediate container cc08d129eeb3
---> 842678ca5d49
Step 8/8 : ENTRYPOINT /bin/bash
---> Running in 20b92a97c8a8
Removing intermediate container 20b92a97c8a8
---> fefd0d665677
Successfully built fefd0d665677
Successfully tagged yandex:user5

最佳答案

问题是使用基础镜像中的卷:

Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



This

关于docker - Dockerfile:通过RUN对文件系统所做的更改不会持久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com