【发布时间】:2018-05-04 16:54:12
【问题描述】:
我有一个 Dockerfile 如下:
FROM jenkins/jenkins:2.119
USER jenkins
ENV HOME /var/jenkins_home
COPY --chown=jenkins:jenkins ssh ${HOME}/.ssh/
RUN chmod 700 ${HOME}/.ssh && \
chmod 600 ${HOME}/.ssh/*
ssh 目录在构建机器的 dir/file 上有 755/644。但是,当我使用
docker build -t my/temp .
并使用 ls 命令启动映像
docker run -it --rm my/temp ls -la /var/jenkins_home/.ssh
chmod 命令都不应用于图像
drwxr-xr-x 2 jenkins jenkins 4096 May 3 12:46 .
drwxr-xr-x 4 jenkins jenkins 4096 May 3 12:46 ..
-rw-r--r-- 1 jenkins jenkins 391 May 3 11:42 known_hosts
在构建过程中我看到
Step 4/6 : COPY --chown=jenkins:jenkins ssh ${HOME}/.ssh/
---> 58e0d8242fac
Step 5/6 : RUN chmod 700 ${HOME}/.ssh && chmod 600 ${HOME}/.ssh/*
---> Running in 0c805d4d4252
Removing intermediate container 0c805d4d4252
---> bbfc828ace79
看起来 chmod 已被丢弃。我怎样才能阻止这种情况发生?
我在 Mac OSX 上使用最新的 Docker (Edge) 版本 18.05.0-ce-rc1-mac63 (24246);边缘 3b5a9a44cd
编辑
使用 --rm 也不起作用(在删除图像并重建之后)但没有收到删除消息
docker build -t my/temp --rm=false .
run -it --rm my/temp ls -la /var/jenkins_home/.ssh
drwxr-xr-x 2 jenkins jenkins 4096 May 3 15:42 .
drwxr-xr-x 4 jenkins jenkins 4096 May 3 15:42 ..
-rw-r--r-- 1 jenkins jenkins 391 May 3 11:42 known_hosts
编辑 2
所以基本上是 Docker 中的一个错误,其中带有 VOLUME 的基本映像导致 chmod 失败,并且类似地在卷上运行 mkdir 失败,但 COPY 失败了,但留下了错误权限的目录。感谢bkconrad。
编辑 3
在这里创建了带有修复的分支https://github.com/systematicmethods/jenkins-docker build.sh 会在本地构建镜像
【问题讨论】:
标签: docker dockerfile