Dockerfile - 用于切换主目录的 Docker 指令

ove*_*nge 8 docker dockerfile

对于以下 dockerfile:

\n\n
FROM buildpack-deps:buster\n\nRUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam\n\n# Update and allow for apt over HTTPS\nRUN apt-get update && \\\n  apt-get install -y apt-utils\nRUN apt-get install -y apt-transport-https\nRUN apt update -y \nRUN apt install python3-pip -y\n\n# switch user from 'root' to \xe2\x80\x98someteam\xe2\x80\x99 and also to the home directory that it owns \nUSER someteam\n\nRUN pwd \n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

USER只更改用户但不更改主目录

\n\n

编辑:

\n\n
Step 11/14 : WORKDIR $HOME\ncannot normalize nothing\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何将主目录更改为/home/someteam

\n

Adi*_*iii 7

您可以WORKDIR在 dockerfile 中使用更改用户目录,这将成为工作目录。因此,每当您创建容器时,工作目录都将是传递给WORKDIRDockerfile 中的指令的目录。

\n\n

工作目录

\n\n

WORKDIR 指令的 Dockerfile 参考

\n\n
\n

为了清晰和可靠,您应该始终使用 WORKDIR 的绝对路径。另外,您应该使用 WORKDIR 而不是大量的指令,例如 RUN cd \xe2\x80\xa6 && do-something,这些指令难以阅读、故障排除和维护。

\n
\n\n
FROM buildpack-deps:buster\n\nRUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam\n\n# Update and allow for apt over HTTPS\nRUN apt-get update && \\\n  apt-get install -y apt-utils\nRUN apt-get install -y apt-transport-https\nRUN apt update -y \nRUN apt install python3-pip -y\n\n# switch user from \'root\' to \xe2\x80\x98someteam\xe2\x80\x99 and also to the home directory that it owns \nUSER someteam\nWORKDIR /home/someteam\n
Run Code Online (Sandbox Code Playgroud)\n\n

在此输入图像描述

\n\n

使用 $HOME 会导致错误。

\n\n
\n

当您使用 USER 指令时,它会影响用于在容器内启动新命令的用户 ID。最好的选择是在 Dockerfile 中设置 ENV\n HOME /home/aptly,这将起作用dockerfile-home-is-不使用添加复制指令

\n
\n