我可以在一个 Docker 容器中运行多个程序吗? [英] Can I run multiple programs in a Docker container?

查看:75
本文介绍了我可以在一个 Docker 容器中运行多个程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从部署旨在在桌面用户上运行的应用程序的角度来了解 Docker.我的应用程序只是一个 Flask Web 应用程序和 mongo 数据库.通常我会同时安装在 VM 中,并将主机端口转发到来宾 Web 应用程序.我想尝试一下 Docker,但我不确定我打算如何使用多个程序.文档说只能有 ENTRYPOINT 所以我怎么能有 Mongo 和我的烧瓶应用程序.或者它们是否需要位于单独的容器中,在这种情况下它们如何相互通信以及这如何使分发应用程序变得容易?

I'm trying to wrap my head around Docker from the point of deploying an application which is intended to run on the users on desktop. My application is simply a flask web application and mongo database. Normally I would install both in a VM and, forward a host port to the guest web app. I'd like to give Docker a try but I'm not sure how I'm meant to use more than one program. The documentations says there can only be only ENTRYPOINT so how can I have Mongo and my flask application. Or do they need to be in separate containers, in which case how do they talk to each other and how does this make distributing the app easy?

推荐答案

只能有一个 ENTRYPOINT,但该目标通常是一个脚本,该脚本可启动所需数量的程序.您还可以使用例如 Supervisord 或类似方法来处理在单个容器内启动多个服务.这是一个在单个容器中运行 mysql、apache 和 wordpress 的 docker 容器示例.

There can be only one ENTRYPOINT, but that target is usually a script that launches as many programs that are needed. You can additionally use for example Supervisord or similar to take care of launching multiple services inside single container. This is an example of a docker container running mysql, apache and wordpress within a single container.

假设您有一个供单个 Web 应用程序使用的数据库.那么在单个容器中运行两者可能更容易.

Say, You have one database that is used by a single web application. Then it is probably easier to run both in a single container.

如果您有一个被多个应用程序使用的共享数据库,那么最好将数据库运行在自己的容器中,而每个应用程序都运行在自己的容器中.

If You have a shared database that is used by more than one application, then it would be better to run the database in its own container and the applications each in their own containers.

当应用程序在不同的容器中运行时,它们之间至少有两种可能性:

There are at least two possibilities how the applications can communicate with each other when they are running in different containers:

  1. 使用公开的 IP 端口并通过它们进行连接.
  2. 最近的 docker 版本支持链接.

这篇关于我可以在一个 Docker 容器中运行多个程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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