在mkdir之后触摸文件时,构建Dockerfile失败 [英] Building Dockerfile fails when touching a file after a mkdir
问题描述
我是Docker的新人,尝试用简单的Dockerfile构建一个图像:
I'm new to Docker and try to build an image with a simple Dockerfile:
FROM jenkins
USER root
RUN mkdir -pv /home/a/b
RUN touch /home/a/b/test.txt
RUN mkdir -pv /var/jenkins_home/a/b
RUN touch /var/jenkins_home/a/b/test.txt
USER jenkins
当我构建它,它失败与以下输出:
When I build it, it fails with the following output:
Step 0 : FROM jenkins
Step 1 : USER root
Step 2 : RUN mkdir -pv /home/a/b
mkdir: created directory '/home/a'
mkdir: created directory '/home/a/b'
Step 3 : RUN touch /home/a/b/test.txt
Step 4 : RUN mkdir -pv /var/jenkins_home/a/b
mkdir: created directory '/var/jenkins_home/a'
mkdir: created directory '/var/jenkins_home/a/b'
Step 5 : RUN touch /var/jenkins_home/a/b/test.txt
touch: cannot touch '/var/jenkins_home/a/b/test.txt': No such file or directory
任何人告诉我,我在这里失踪了为什么第一个mkdir&触摸组合工作,第二个不是?
Can anyone tell me, what I am missing here? Why does the first mkdir & touch combination work and the second does not?
推荐答案
查看 https://registry.hub.docker.com/u/library/jenkins/ ,似乎/ var / jenkins_home是一个卷。您只能在容器运行时创建文件,可能是使用卷映射,如
Looking at https://registry.hub.docker.com/u/library/jenkins/, it seems that /var/jenkins_home is a volume. You can only create files there while the container is running, presumably with a volume mapping like
docker run ... -v /your/jenkins/home:/var/jenkins_home ...
docker构建过程对于共享卷。
The docker build process knows nothing about shared volumes.
这篇关于在mkdir之后触摸文件时,构建Dockerfile失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!