简体   繁体   English

distroless 镜像中的 nobody 和非 root 用户

[英]nobody & nonroot user in distroless images

Distroless images comes with 3 users: Distroless 镜像附带 3 个用户:

> docker run --rm --entrypoint cat gcr.io/distroless/nodejs:debug /etc/passwd
root:x:0:0:root:/root:/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin
nonroot:x:65532:65532:nonroot:/home/nonroot:/sbin/nologin

If you run the image without a USER instruction in your Dockerfile the image runs as uid=0(root) gid=0(root) .如果您在Dockerfile中没有USER指令运行图像,图像将以uid=0(root) gid=0(root)运行。

I would like to avoid this and use an unprivileged user.我想避免这种情况并使用非特权用户。

Other than nobody not having a /home directory, what is the difference between using USER nobody and USER nonroot in my Dockerfile?除了nobody没有/home目录之外,在我的 Dockerfile 中使用USER nobodyUSER nonroot有什么区别?

There are 2 type of distroless images which can be used in production:有两种类型的 distroless 映像可用于生产:

with latest tag带有最新标签
This image say, gcr.io/distroless/base by default has "Config.User: 0" and "Config.WorkingDir: /" config in it and if you don't use USER for switching the user to nonroot user which is defined in it or it will start container with root user.这个图像说,默认情况下gcr.io/distroless/base有“Config.User:0”和“Config.WorkingDir:/”配置,如果你不使用USER将用户切换到定义的nonroot用户在其中,否则它将以root用户启动容器。

with nonroot tag带非根标签
This image say, gcr.io/distroless/base:nonroot by default has "Config.User: 65532" and "Config.WorkingDir: /home/nonroot" config in it and there is no need to use USER for changing user to non-root user.这张图片说, gcr.io/distroless/base:nonroot /distroless/base:nonroot 默认情况下有“Config.User: 65532”和“Config.WorkingDir: /home/nonroot”配置,不需要使用USER将用户更改为非-根用户。
PS: maybe you need to change ownership of copied files in multistage build to nonroot user. PS:也许您需要将多阶段构建中复制文件的所有权更改nonroot用户。

nobody user没有人用户
purpose of nobody user in not related to distroless images and it's about Linux itself which described here very well nobody 用户的目的与 distroless 图像无关,它是关于 Linux 本身的,这里描述得很好

The best practice seems to be using nonroot user.最佳实践似乎是使用nonroot用户。

references :参考资料

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM