本文介绍了Dockerfile:通过RUN对文件系统所做的更改不会持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过Web搜索到 site:stackoverflow.com dockerfile RUN fs更改的伪造。

I could not find that spoecifics via web search for site:stackoverflow.com dockerfile RUN fs changes not persisted.

我制作了 Dockerfile ,并希望通过 RUN 在映像中进行一些更改。首先,我想更改文件属性,但是启动容器中没有更改。我发现此帖子大约针对 chmod docker 错误和解决方法:。但是,现在我只是尝试通过 Dockerfile 中的 RUN touch / path / file 创建文件,并且已经在下一个命令中了(据我了解文档的理解,是Docker的下一层)更改(该文件)已消失。就我所知,这很奇怪,否则 apt install 会如何工作,因为它将对映像中的文件系统进行更改...为什么该特定 RUN 不持久吗?下面的文档说的相反(或者我误解了 commit 的含义):

I made Dockerfile and wanted to make some changes in image via RUN. Firstly I wanted to change file attributes, but changes were not there in started container. I've found this post taking about docker bug for chmod and workarounds: https://serverfault.com/questions/772227/chmod-not-working-correctly-in-docker. However, now I just try to create a file via RUN touch /path/file in Dockerfile and already on next command (next layer for docker as I understood the docs) changes (that file) are gone. As far as I see it is strange, otherwise how apt install works then because it will make changes to file system in the image... Why results of that particular RUN do not persist? Docs below tell opposite (or I misunderstand meaning of commit here):

此处输出为 docker build --no-cache -t yandex:user5 yandex2 / (请参阅步骤6和7;创建dockeruser, btw ):

Here is output of docker build --no-cache -t yandex:user5 yandex2/ (see steps 6 and 7; dockeruser is created, btw):

Step 1/8 : FROM artifactory.dev.foo.org:5000/yandex-tank:jmeter
 ---> b8286a9220ca
Step 2/8 : LABEL maintainer="[email protected]"
 ---> 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


推荐答案

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

The Problem is using the volumes in the base image:

参见

这篇关于Dockerfile:通过RUN对文件系统所做的更改不会持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:27