简体   繁体   English

从 docker 容器在主机上运行 docker 容器

[英]Running a docker container on the host from a docker container

I'm trying to dockerize 2 dotnet console application that one depends on the other.我正在尝试对 2 个依赖于另一个的 dotnet 控制台应用程序进行 dockerize。 When I run the 1st container I need it to run another container on the host, insert a parameter to it's stdin and wait for it to end the job and exit.当我运行第一个容器时,我需要它在主机上运行另一个容器,向它的标准输入插入一个参数并等待它结束作业并退出。 What will be the best solution to achieve this?实现这一目标的最佳解决方案是什么?

Running a container inside a container seems to me like a bad solution, I've also thought about managing another process with a webserver (nginx or something) on the host that get the request as http request and execute a docker run command in the host but I'm sure there is a better solution for this (in this way the webserver will just run on the host and not inside a container).在容器内运行容器对我来说似乎是一个糟糕的解决方案,我还考虑过使用主机上的网络服务器(nginx 或其他东西)管理另一个进程,该进程将请求作为 http 请求并在主机中执行 docker 运行命令但我确信对此有更好的解决方案(这样,网络服务器将只在主机上运行,而不是在容器内)。

There is also this solution but it seems to have major security issues.也有这个解决方案,但它似乎有重大的安全问题。

I've tried also using the Docker.DotNet library but it does not help with my problem.我也尝试过使用 Docker.DotNet 库,但它对我的问题没有帮助。 any ideas for the best solution?最好的解决方案有什么想法吗? Thanks in advance.提前致谢。

EDIT:编辑:

I will be using docker compose but the problem is that the 2nd container is not running and listening at all time, similar to the Hello-World container it's called, performs it's job and exits.我将使用 docker 组合,但问题是第二个容器始终没有运行和监听,类似于它所调用的 Hello-World 容器,执行它的工作并退出。

EDIT2: FIX EDIT2:修复

I've implemented redis as a message broker to communicate between the different services, while it changed the requirement a little (containers will always run and listen to redis) it helped me to solve the issue.我已经实现了 redis 作为消息代理来在不同的服务之间进行通信,虽然它稍微改变了要求(容器将始终运行并监听 redis),但它帮助我解决了这个问题。

I am not sure I understand correctly what you need to do, but if you simply need to start two containers in parallel the simplest way I can think of is docker-compose .我不确定我是否正确理解您需要做什么,但如果您只需要并行启动两个容器,我能想到的最简单的方法是docker-compose

Another way is with a python or bash/bat script that launches the containers independently (in python you can either use the Docker API or do it manually with the subprocess module). Another way is with a python or bash/bat script that launches the containers independently (in python you can either use the Docker API or do it manually with the subprocess module). This allows you to perform other things (like writing on the stdin of one container, as you stated).这允许您执行其他操作(如您所说,在一个容器的标准输入上写入)。

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

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