[英]Docker: docker: Error response from daemon: linux spec user: unable to find user myuser: no matching entries in passwd file
[root@mymachine redisc]# docker run -p 6379:6379 --user myuser redisc
docker: Error response from daemon: linux spec user: unable to find user myuser: no matching entries in passwd file.
but i can become myuser on the host但我可以成为主机上的 myuser
[root@mymachine redisc]# sudo su myuser
[myuser@mymachine redisc]#
How would i be able to run as myuser in the container?我如何才能在容器中以 myuser 身份运行?
The host and the container are completely separate.主机和容器是完全分开的。 You need to create myuser
inside the redisc container before you try and run stuff as that user.在尝试以该用户身份运行内容之前,您需要在 redisc 容器内创建myuser
。
According to the documentation you can use the ID of the user / group:根据文档,您可以使用用户/组的 ID:
When passing a numeric ID, the user does not have to exist in the container.传递数字 ID 时,用户不必存在于容器中。
Source: https://docs.docker.com/engine/reference/run/#user来源: https : //docs.docker.com/engine/reference/run/#user
The command could look like this:该命令可能如下所示:
docker run -p 6379:6379 --user 1001 redisc
You can mount read-only the host user info您可以以只读方式挂载主机用户信息
# user user and group IDs:
usr="--user $(id -u myuser):$(id -g myuser)"
mountdirs="-v /etc/passwd:/etc/passwd:ro -v /etc/shadow:/etc/shadow:ro -v /etc/group:/etc/group:ro"
options="-p 6379:6379"
# I use
# options="-ti --rm --entrypoint=/bin/bash"
image=redisc
docker run ${options} ${usr} ${mountdirs} -w /home/myuser "${image}"
[root@host ~]# docker run --user=toto -ti fedora:26 uname [root@host ~]# docker run --user=toto -ti fedora:26 uname
/usr/bin/docker-current: Error response from daemon: linux spec user: unable to find user toto: no matching entries in passwd file. /usr/bin/docker-current:来自守护进程的错误响应:linux 规范用户:无法找到用户 toto:passwd 文件中没有匹配的条目。
[root@host ~]# docker run --user=
id -u toto
-ti fedora:26 uname [root@host ~]# docker run --user=id -u toto
-ti fedora:26 unameLinux Linux
I mistakenly thought a permission denied error was about access to my filesystem.我错误地认为权限被拒绝错误与访问我的文件系统有关。 I built a container that has a bash script as the entrypoint, but didn't give myself execution permission before building the image.我构建了一个以 bash 脚本作为入口点的容器,但在构建映像之前没有给自己执行权限。
chmod +x entrypoint.sh
and rebuilding the image solved my issue. chmod +x entrypoint.sh
并重建图像解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.