一个容器中有多个图像 [英] Multiple images inside one container

查看:53
本文介绍了一个容器中有多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这就是问题所在,我需要进行一些开发,为此,我需要以下软件包:

So, here is the problem, I need to do some development and for that I need following packages:


  1. MongoDb

  2. NodeJs

  3. Nginx

  4. RabbitMq

  5. Redis

  1. MongoDb
  2. NodeJs
  3. Nginx
  4. RabbitMq
  5. Redis

一种选择是我拍摄Ubuntu映像创建一个容器,并开始一个接一个地完成安装,启动我的服务器,并暴露端口。

One option is that I take a Ubuntu image, create a container and start installing them one by one and done, start my server, and expose the ports.

但这可以轻松完成一个虚拟盒子,它将不会使用Docker的功能。因此,我必须开始使用这些软件包构建自己的映像。现在,这是一个问题,如果我开始编写我的Dockerfile,并且是否将其中要下载Node js(及其他)的命令放在其中,这又变得像虚拟化一样。

But this can easily be done in a virtual box also, and it will not going to use the power of Docker. So for that I have to start building my own image with these packages. Now here is the question if I start writing my Dockerfile and if place the commands to download the Node js (and others) inside of it, this again becomes the same thing like virtualization.

我需要的是从Ubuntu开始,并继续添加 MongoDb,NodeJs,RabbitMq,Nginx的引用 Dockerfile 中的Redis ,最后将各个端口暴露出来。

What I need is that I start from Ubuntu and keep on adding the references of MongoDb, NodeJs, RabbitMq, Nginx and Redis inside the Dockerfile and finally expose the respective ports out.

以下是我要查询的内容:

Here are the queries I have:


  1. 这可能吗?就像从一个基本映像开始时在Dockerfile中添加其他映像的引用一样。

  2. 如果是,那么如何?

  3. 这也是

  4. 如何在Docker中做这些事情?

  1. Is this possible? Like adding the refrences of other images inside the Dockerfile when you are starting FROM one base image.
  2. If yes then how?
  3. Also is this the correct practice or not?
  4. How to do these kind of things in Docker ?

谢谢

推荐答案

使图像保持明亮。每个容器运行一项服务。在docker hub上使用mongodb,nodejs,rabbitmq,nginx等官方镜像。如有需要,请对其进行扩展。如果您想在胖容器中运行所有内容,则最好只使用VM。

Keep images light. Run one service per container. Use the official images on docker hub for mongodb, nodejs, rabbitmq, nginx etc. Extend them if needed. If you want to run everything in a fat container you might as well just use a VM.

您当然可以在开发设置中做疯狂的事情,但是为什么要花时间在生产环境中设置值的东西?如果您需要扩展其中一项服务怎么办?如何在每个服务上设置内存和cpu约束? ..然后列表继续。

You can of course do crazy stuff in a dev setup, but why spend time setting up something that has zero value in a production environment? What if you need to scale up one of the services? How do set memory and cpu constraints on each service? .. and the list goes on.

不要制造整体容器。

一个好的开始是使用docker-compose配置可以互相通信的一组服务。您可以为 docker-compose.yml 文件制作产品和开发版本。

A good start is to use docker-compose to configure a set of services that can talk to each other. You can make a prod and dev version of your docker-compose.yml file.

正确的心态

在理想的环境中,您将在生产环境中的集群环境中运行容器,以便能够扩展系统并具有并发性,但是根据您的运行情况,这可能会过大。最好将它放在脑后,因为它可以帮助您做出正确的决定。

In a perfect world you would run your containers in clustered environment in production to be able to scale your system and have concurrency, but that might be overkill depending on what you are running. It's at least good to have this in the back of your head because it can help you to make the right decisions.

要想成为一名企业家,需要考虑一些要点。 purist:

Some points to think about if you want to be a purist :


  • 如何在多个主机之间进行持久卷存储?

  • 反向代理/负载平衡器可能应该是使用内部网络与容器通信的系统的入口点。

  • 我的服务甚至可以在集群环境(容器的多个实例)中运行 li>
  • How do you have persistent volume storage across multiple hosts?
  • Reverse proxy / load balancer should probably be the entry point into the system that talks to the containers using the internal network.
  • Is my service even able run in a clustered environment (multiple instances of the container)

当然,您可以在开发人员中做一些肮脏的事情,例如在主机卷中映射以进行持久存储(以及许多在产品中使用docker Standalone的人

You can of course do dirty things in dev such as mapping in host volumes for persistent storage (and many people who use docker standalone in prod do that as well).

理想情况下,我们应该将docker in dev和docker i prod分开。 Docker是开发过程中的绝佳工具,因为您可以启动Redis,memcached,postgres,mongodb,rabbitmq,node或其他任何东西,并在几分钟之内运行,从而与团队的其他成员共享设置。产品中的Docker可以是完全不同的野兽。

Ideally we should separate docker in dev and docker i prod. Docker is a fantastic tool during development as you can have redis, memcached, postgres, mongodb, rabbitmq, node or whatnot up and running in minutes sharing that compose setup with the rest of the team. Docker in prod can be a completely different beast.

我还想补充一点,我通常反对狂热主义,即产品中的一切都应在Docker中运行 。在有意义的情况下在docker中运行服务。大型公司制作自己的基本图像也很常见。这可能是很多工作,并且需要维护以跟上安全修复程序等的工作。从docker启动时,这不一定是您要跳的第一件事。

I would also like to add that I'm generally against the fanaticism that "everything should be running in docker" in prod. Run services in docker when it makes sense. It's also not uncommon for larger companies to make their own base images. This can be a lot of work and will require maintenance to keep up with security fixes etc. It's not necessarily the first thing you jump on when starting with docker.

这篇关于一个容器中有多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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