【Docker】Dockerfile 之 USER


參考教程:https://docs.docker.com/engine/reference/builder/

環境

  1. virtual box 6.1
  2. centos 7.8
  3. 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 中跟隨該鏡像的所有 RUNCMDENTRYPOINT 指令。

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 指令的用法和注意事項。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM