对于以下dockerfile:
FROM buildpack-deps:buster
RUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam
# Update and allow for apt over HTTPS
RUN apt-get update && \
apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN apt update -y
RUN apt install python3-pip -y
# switch user from 'root' to ‘someteam’ and also to the home directory that it owns
USER someteam
RUN pwd
USER
仅更改用户,而不更改主目录
Step 11/14 : WORKDIR $HOME
cannot normalize nothing
如何将主目录更改为/home/someteam
?
答案 0 :(得分:0)
您可以使用dockerfile中的WORKDIR
更改用户目录,该目录将成为工作目录。因此,无论何时创建容器,工作目录都会成为Dockerfile中传递给WORKDIR
指令的目录。
WORKDIR
关于WORKDIR指令的Dockerfile参考
为清楚起见,请始终使用绝对路径 您的WORKDIR。另外,您应该使用WORKDIR而不是扩散 指令RUN cd…&& do-something,这些指令很难阅读, 进行故障排除和维护。
FROM buildpack-deps:buster
RUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam
# Update and allow for apt over HTTPS
RUN apt-get update && \
apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN apt update -y
RUN apt install python3-pip -y
# switch user from 'root' to ‘someteam’ and also to the home directory that it owns
USER someteam
WORKDIR /home/someteam
使用$ HOME将导致错误。
使用USER指令时,它会影响用于启动的用户ID 容器中的新命令。最好的选择是设置ENV HOME / home /适当地放置在您的Dockerfile中,它将dockerfile-home-is-not-working-with-add-copy-instructions工作