參考教程:https://docs.docker.com/engine/reference/builder/
環境
- virtual box 6.1
- centos 7.8
- docker 19.03
USER
USER <user>[:<group>]
or
USER <UID>[:<GID>]
The USER instruction sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.
USER 指令設置運行鏡像時要使用的用戶名(或 UID)以及可選的用戶組(或 GID),以及 Dockerfile 中跟隨該鏡像的所有 RUN,CMD 和 ENTRYPOINT 指令。
Note that when specifying a group for the user, the user will have only the specified group membership. Any other configured group memberships will be ignored.
請注意,在為用戶指定組時,用戶將僅具有指定的組成員身份。任何其它已配置的組成員身份將被忽略。
Warning
When the user doesn’t have a primary group then the image (or the next instructions) will be run with the
rootgroup.On Windows, the user must be created first if it’s not a built-in account. This can be done with the
net usercommand called as part of a Dockerfile.
警告
當用戶沒有主要組時,該鏡像(或后續指令)將與
root組一起運行。在 Windows 上,如果不是內置帳戶,則必須首先創建該用戶。這可以通過作為 Dockerfile 的一部分調用的e
net user命令來完成。
FROM microsoft/windowsservercore
# Create Windows user in the container
RUN net user /add patrick
# Set it for subsequent commands
USER patrick
總結
介紹了 Dockerfile 中 USER 指令的用法和注意事項。
