一个容器内的多个图像 [英] Multiple images inside one container

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

问题描述

所以,问题来了,我需要进行一些开发,为此我需要以下软件包:

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

一种选择是我获取一个 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的引用和 RedisDockerfile 中,最后将各自的端口暴露出来.

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.

以下是我的疑问:

  1. 这可能吗?就像从一个基础镜像开始时在 Dockerfile 中添加其他镜像的引用一样.
  2. 如果是,那怎么办?
  3. 这也是正确的做法吗?
  4. 如何在 Docker 中做这些事情?

提前致谢.

推荐答案

保持图像明亮.每个容器运行一项服务.使用 docker hub 上的官方镜像,用于 mongodb、nodejs、rabbitmq、nginx 等.如果需要,可以扩展它们.如果您想在胖容器中运行所有内容,不妨只使用虚拟机.

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 文件的 prod 和 dev 版本.

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.

如果你想成为一个纯粹主义者,需要考虑的几点:

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

  • 如何跨多个主机进行持久卷存储?
  • 反向代理/负载平衡器应该是系统的入口点,它使用内部网络与容器通信.
  • 我的服务是否甚至可以在集群环境中运行(容器的多个实例)

您当然可以在 dev 中做一些肮脏的事情,例如在主机卷中映射以进行持久存储(许多在 prod 中使用 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 或诸如此类的东西,并与团队的其他成员共享该组合设置.prod 中的 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.

我还想补充一点,我通常反对 prod 中一切都应该在 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天全站免登陆