简体   繁体   English

从另一个 Docker 容器内部生成 Docker 容器的最佳方法?

[英]Best way to spawn a Docker container from inside another Docker container?

I have a node.js Websocket server listening on port 443 running in a Docker Container(let's say ws_container) that is connected to both the host network and an internal network, let's say internal_net.我有一个 node.js Websocket 服务器在侦听端口 443,该服务器在 Docker 容器中运行(假设是 ws_container)和一个内部网络,它连接到主机网络。

When the Websocket server running in ws_container establish a connection with a Websocket, I want to spawn a new container(let's say an Ubuntu 18.04 container) connected to internal_net from the ws_container.当在 ws_container 中运行的 Websocket 服务器与 Websocket 建立连接时,我想生成一个新容器(比如说一个 Ubuntu 容器)

I came across this question Is it possible to start a stopped container from another container , that states the best way to accomplish this is to mount the docker socket in the container(in my case ws_container).我遇到了这个问题Is it possible to start a stopped container from another container ,说明实现此目的的最佳方法是将 docker 套接字安装在容器中(在我的情况下为 ws_container)。

Are there any better ways of solving the problem?有没有更好的方法来解决这个问题?

It depends where you want to spawn container.这取决于您要在哪里生成容器。 Containers run where docker daemon runs.容器在 docker 守护程序运行的地方运行。 To connect to the daemon you can use socket if the daemon is on same machine or you can use tcp connection to spawn container on any daemon that you have access to.要连接到守护程序,如果守护程序在同一台机器上,您可以使用套接字,或者您可以使用 tcp 连接在您有权访问的任何守护程序上生成容器。

If you use some kind of orchestration like swarm or kubernetes then you can use some management tools to do that, like portainer, open shift or others.如果您使用某种编排方式,例如 swarm 或 kubernetes,那么您可以使用一些管理工具来执行此操作,例如 portainer、open shift 或其他。

However in most of the cases mapping socket is the easiest and sufficient option to do.然而,在大多数情况下,映射套接字是最简单且足够的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM