Docker 中的非 root 用户 [英] Non-root user in Docker
本文介绍了Docker 中的非 root 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本的 Dockerfile:
I have a basic Dockerfile:
FROM ubuntu:xenial
USER test
ENTRYPOINT ["/bin/bash"]
对于这个 Dockerfile,我希望能够创建一个没有密码的用户,并且当 Docker 容器运行时,我希望使用该用户,而不是 root.当我尝试运行容器 docker run -it test:1
时,我收到此错误:
For this Dockerfile, I want to be able to create a user without a password, and when the Docker container is run, I want that user to be used, instead of root. When I try to run the container, docker run -it test:1
, I get this error:
docker: Error response from daemon: linux spec user: unable to find user test: no matching entries in passwd file.
如何在 Dockerfile 中创建用户并在容器交互运行时让该用户成为默认用户?
How can I create a user in a Dockerfile and have that user be the default user when the container is run interactively?
推荐答案
在USER指令前添加RUN useradd -s/bin/bash user
.
这篇关于Docker 中的非 root 用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文