Dockerfile-切换主目录的Docker指令

时间:2019-07-26 20:57:22

标签: docker dockerfile

对于以下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

1 个答案:

答案 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

enter image description here

使用$ HOME将导致错误。

  

使用USER指令时,它会影响用于启动的用户ID   容器中的新命令。最好的选择是设置ENV   HOME / home /适当地放置在您的Dockerfile中,它将dockerfile-home-is-not-working-with-add-copy-instructions工作

相关问题