从docker容器运行docker命令(Running docker command from docker container)

编程入门 行业动态 更新时间:2024-10-26 17:35:59
从docker容器运行docker命令(Running docker command from docker container)

需要编写一个在dock-a中安装docker的Dockerfile。 因为container-a需要执行docker命令到container-b,它与container-a一起运行。 我的理解是你在编写Dockerfile时不应该使用“sudo”。 但我陷入困境 - 我指派给docker组的用户是什么? 当您运行docker exec -it ,您将自动为root。

sudo usermod -a -G docker whatuser?

另外(我在集装箱内手动尝试这个 - 看它是否有效)你必须做一个newgrp docker来激活对组的更改。 我这样做的任何时候,当我没有sudo'ed时,我最终sudo'ing。 那有意义吗? 症状是 - 我去exit容器,我必须退出两次(好像我改变了用户)。

我究竟做错了什么?

Need to write a Dockerfile that installs docker in container-a. Because container-a needs to execute a docker command to container-b that's running alongside container-a. My understanding is you're not supposed to use "sudo" when writing the Dockerfile. But I'm getting stuck -- what user to I assign to docker group? When you run docker exec -it, you are automatically root.

sudo usermod -a -G docker whatuser?

Also (and I'm trying this out manually inside container-a to see if it even works) you have to do a newgrp docker to activate the changes to groups. Anytime I do that, I end up sudo'ing when I haven't sudo'ed. Does that make sense? The symptom is -- I go to exit the container, and I have to exit twice (as if I changed users).

What am I doing wrong?

最满意答案

如果您尝试将容器并排运行(不是容器内的容器),则应该从主机系统安装docker socket并以这种方式执行命令到其他容器:

docker run --name containera \ -v /var/run/docker.sock:/var/run/docker.sock \ yourimage

安装了docker socket后,您可以控制主机系统上的docker。

If you are trying to run the containers alongside one another (not container inside container), you should mount the docker socket from the host system and execute commands to other containers that way:

docker run --name containera \ -v /var/run/docker.sock:/var/run/docker.sock \ yourimage

With the the docker socket mounted you can control docker on the host system.

更多推荐

本文发布于:2023-08-06 21:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   命令   docker   container   command

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!