【Docker】Dockerfile 之 USER
參考教程: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
root
group.On Windows, the user must be created first if it’s not a built-in account. This can be done with the
net user
command 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 指令的用法和注意事項。