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

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

问题描述

我正在尝试将Docker放在Docker上,从部署应用程序的角度出发,该应用程序旨在在桌面用户上运行。我的应用程序只是一个瓶子Web应用程序和mongo数据库。通常我将安装在虚拟机中,并将主机端口转发到访客网络应用程序。我想给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 contains, 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. 最近的码头版本支持链接

  1. Use exposed IP ports and connect via them.
  2. Recent docker versions support linking.

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

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