Dockerfile : changes made to filesystem via RUN do not persist

标签 docker

我无法通过网络搜索 site:stackoverflow.com dockerfile RUN fs changes not persisted 找到该具体信息.

我做了Dockerfile并想通过RUN对图像进行一些更改。首先,我想更改文件属性,但启动的容器中没有更改。我发现这篇文章大约需要 docker chmod 的错误和解决方法: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="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44222b2b04222b2b6a2b3623" rel="noreferrer noopener nofollow">[email protected]</a>"
 ---> 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

关于Dockerfile : changes made to filesystem via RUN do not persist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099955/

相关文章:

docker - 如何在 hyperledger fabric 中使用 openldap 和 fabric-ca?

docker - 在不同的用户下启动docker容器

python - 子进程在 docker 容器中不起作用

linux - Dockerfile ADD tar.gz 不会在带有 Docker 的 ubuntu VM 上提取

linux - 在 Docker compose 中限制可用的主机资源而不使用 swarm

macos - osx上的Gradle Docker插件中断管道

docker - 创建最小的Docker容器的最佳实践

docker - 您如何使用Gradle Docker插件在Windows中使用提供的Dockerfile构建Docker镜像?

logging - 将 docker-compose 日志保存到文件

docker - asp net core docker serilog配置