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

posted @   jiangbo4444  阅读(5835)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示