是否有可能从容器到主机执行Docker调用?

人气:770 发布:2022-09-21 标签: docker

问题描述

我想能够,例如,从容器内重新启动主机容器。

I would like to be able to, e.g., restart host containers from inside a container.

有谁知道是否有任何方法可以做到这一点? / p>

Does anyone know whether there is any way I could do that?

推荐答案

假设你的问题是是否有可能从容器到主机执行Docker调用?

是的,一定可以! 与Docker守护程序的通信通过一个套接字。默认情况下,该套接字是 unix:///var/run/docker.sock 。您的管理器容器只需要访问(和许可)到此套接字。

Yeah, sure it is possible! The communication with the Docker daemon goes through a socket. By default this socket is the unix:///var/run/docker.sock. Your manager-container just need access (and permission) to this socket.

请注意,Docker守护程序的选项(我正在查看ou -H,--host )允许通过 TCP (或甚至 fd )。

Note that an option of the Docker daemon (I'm looking at ou -H, --host) allows the communication through TCP (or even a fd).

然后您只需要一个Docker客户端(任何Docker API实现)进行通信。

You then just need a Docker client (any Docker API implementation) to communicate.

776