在一个码头容器中运行多个应用程序 [英] Running multiple applications in one docker container

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

问题描述

这个问题是我继续探索Docker的一部分,在某种程度上跟随着我的一个早期问题。现在我已经了解了如何通过将一大堆Docker容器连接在一起,从而获得一个完整的应用程序堆栈(实际上是一个迷你VPS)。例如,可以创建一个堆栈,它为Apache + PHP5提供了一些扩展名+ Redis + MemCached + MySQL,所有这些都运行在Ubuntu之上,或者没有附加的数据容器,可以方便地对用户数据进行序列化。

This question is part of my continuing exploration of Docker and in some ways follows up on one of my earlier questions. I have now understood how one can get a full application stack (effectively a mini VPS) working by linking together a bunch of Docker containers. For example one could create a stack that provides Apache + PHP5 with a sheaf of extensions + Redis + MemCached + MySQL all running on top of Ubuntu with or without an additional data container to make it easy to serialize user data.

所有非常漂亮和优雅。但是,我不得不想知道...。 5个容器运行那个小VPS(我计数5不是6,因为Apache + PHP5进入一个容器)。那么假设我有100个这样的VPS运行?这意味着我有500个集装箱运行!我理解这里的论据 - 很容易组合新的应用程序堆栈,更新堆栈的一个组件等。但是,这样做没有不必要的开销?

All very nice and elegant. However, I cannot but help wonder... . 5 containers to run that little VPS (I count 5 not 6 since Apache + PHP5 go into one container). So suppose I have 100 such VPSs running? That means I have 500 containers running! I understand the arguments here - it is easy to compose new app stacks, update one component of the stack etc. But are there no unnecessary overheads to operating this way?

假设我这样做


  • 将所有应用程序放在一个容器内

  • 写一点shell脚本

  • Put all my apps inside one container
  • Write up a little shell script

!/ bin / bash
service memcached start
service redis-server start
....
service apache2 start
while:
do

done

!/bin/bash service memcached start service redis-server start .... service apache2 start while: do : done

在我的Docker文件中我有

In my Dockerfile I have

ADD start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh

....
ENTRYPOINT ["/bin/bash"]
CMD ["/usr/local/bin/start.sh"]

然后我得到该容器运行

docker run -d -p 8080:80 -v /var/droidos/site:/var/www/html -v /var/droidos/logs:/var/log/apache2 droidos/minivps

商业。现在,当我想以编程方式关闭该容器时,我可以通过执行一个单一的docker命令来实现。

and I am in business. Now when I want to shut down that container programmatically I can do so by executing one single docker command.

有一个类似性质的许多问题可以在一个Google为他们除了我以上所述的论点之外,一个应用程序的容器方法的最常见的原因之一是Docker设计工作的方式。我想知道的是,

There are many questions of a similar nature to be found when one Google's for them. Apart from the arguments I have reproduced above one of the commonest reasons given for the one-app-per-container approach is "that is the way Docker is designed to work". What I would like to know


  • 运行x连接容器的x100实例的缺点是什么 - 通过速度,内存使用等进行权衡在主机上?

  • 我在这里做了什么错?

推荐答案

容器基本上是一个进程。在体面的Linux系统上运行500个进程并不存在任何技术问题,尽管它们必须共享CPU和内存。

A container is basically a process. There is no technical issue with running 500 processes on a decent-sized Linux system, although they will have to share the CPU(s) and memory.

容器在一个进程上是一些额外的内核资源来管理名称空间,文件系统和控制组,以及Docker守护程序内的一些管理结构,特别是处理 stdout stderr的

The cost of a container over a process is some extra kernel resources to manage namespaces, file systems and control groups, and some management structures inside the Docker daemon, particularly to handle stdout and stderr.

引入命名空间以提供隔离,以便一个容器不会干扰任何其他容器。如果您的5个容器组成一个不需要隔离的单元,那么您可以使用 - net = container 共享网络命名空间。目前没有功能来分享cgroups,AFAIK。

The namespaces are introduced to provide isolation, so that one container does not interfere with any others. If your groups of 5 containers form a unit that does not need this isolation then you can share the network namespace using --net=container. There is no feature at present to share cgroups, AFAIK.

您的建议有什么问题:


  • 不是码头方式。您可能不重要。

  • 您必须维护脚本才能使其正常工作,担心重新启动过程等,而不是使用为任务设计的业务流程

  • 您将不得不管理文件系统中的冲突,例如两个进程需要不同版本的库,或者它们都写入相同的输出文件。

  • stdout stderr 将混合五个进程

  • it is not "the Docker way". Which may not be important to you.
  • you have to maintain the scripting to get it to work, worry about process restart, etc., as opposed to using an orchestrator designed for the task
  • you will have to manage conflicts in the filesystem, e.g. two processes need different versions of a library, or they both write to the same output file
  • stdout and stderr will be intermingled for the five processes

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

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