当我在切换用户后将entrypoint.sh
复制到主目录时,为什么docker build
仍然将其分配给root
用户:
FROM ubuntu:20.04
SHELL ["/bin/bash", "-c"]
ARG user=hakond
ARG home=/home/$user
RUN useradd --create-home -s /bin/bash $user \
&& echo $user:ubuntu | chpasswd \
&& adduser $user sudo
WORKDIR $home
USER $user
COPY entrypoint.sh $home
RUN ls -l entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
如果我(以hakon
用户身份)构建此文件,则输出为:
$ ls -l entrypoint.sh
-rwxr-xr-x 1 hakon hakon 24 juli 8 14:16 entrypoint.sh
$ echo $USER
hakon
$ docker build -t debug_entrypoint .
[...]
Step 8/10 : COPY entrypoint.sh $home
---> 5f6d16e80d2c
Step 9/10 : RUN ls -l entrypoint.sh
---> Running in ee919e65e860
-rwxr-xr-x 1 root root 24 Jul 8 12:16 entrypoint.sh
[...]
请注意,文件entrypoint.sh
归root
所有(而不是我期望的归hakond
所有)。
发布于 2020-07-08 22:35:48
在ADD或COPY命令中使用可选标志--chown=:。
As copy命令默认使用root
用户。
COPY --chown=$user entrypoint.sh $home
输出应为
Step 13/14 : RUN ls -l entrypoint.sh
---> Running in 231123a8899b
-rwxrwxr-x 1 hakond hakond 0 Jul 8 14:28 entrypoint.sh
https://stackoverflow.com/questions/62794804
复制相似问题