是否可以从另一个容器启动已停止的容器 [英] Is it possible to start a stopped container from another container

查看:90
本文介绍了是否可以从另一个容器启动已停止的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个容器A和B。一旦容器A启动,将执行一个过程,然后容器将停止。容器B只是一个Web应用程序(例如expressjs)。可以从容器B启动A吗?

There are two containers A and B. Once container A starts, one process will be executed, then the container will stop. Container B is just an web application (say expressjs). Is it possible to kickstart A from container B ?

推荐答案

可以向docker授予容器访问权限,以便它可以生成主机上的其他容器。您可以通过在容器内部暴露docker套接字来实现此目的,例如:

It is possible to grant a container access to docker so that it can spawn other containers on your host. You do this by exposing the docker socket inside the container, e.g:

docker run -v /var/run/docker.sock:/var/run/docker.sock --name containerB myimage ...

现在,如果您有容器中的docker 客户端,您将能够控制主机上的docker守护程序,并使用它生成容器A。

Now, if you have the docker client available inside the container, you will be able to control the docker daemon on your host and use that to spawn your "container A".

之前尝试这种方法时,您应该了解安全注意事项:对docker的访问与在主机上具有 root 的访问权限相同,这意味着您的Web应用程序是否存在远程威胁您刚刚将密钥交给了攻击者。 在本文中

Before trying this approach, you should be aware of the security considerations: access to docker is the same as having root access on the host, which means if your web application has a remote compromise you have just handed the keys to your host to the attackers. This is described more fully in this article.

这篇关于是否可以从另一个容器启动已停止的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆