Docker独立容器与耦合容器

时间:2022-08-09 19:18:41

I have a few dozens of php apps that I want to dockerize. I am wondering what will be the best design for management and performance wise.

我有几十个php应用程序需要dockerize。我想知道什么是管理和性能方面的最佳设计。

  1. one big container with all services included (php-fpm, mysql, nginx etc)

    一个包含所有服务的大容器(php-fpm、mysql、nginx等)

  2. separate containers for all services:

    所有服务的独立容器:

    • container-php-fpm-app1
    • container-php-fpm-app1
    • container-nginx-app1
    • container-nginx-app1
    • container-mysql-app1
    • container-mysql-app1
    • container-php-fpm-app2
    • container-php-fpm-app2
    • container-nginx-app2
    • container-nginx-app2
    • container-mysql-app2
    • container-mysql-app2
  3. one container for service, that service hosts all apps:

    一个服务容器,该服务承载所有应用:

    • container-php-fpm - for all php-fpm pools
    • 集装箱-php-fpm -适用于所有php-fpm池
    • container-nginx - for all nginx virtual hosts
    • 容器-nginx -用于所有nginx虚拟主机
    • container-mysql - for all databases
    • 容器-mysql -适用于所有数据库

I understand running separate containers lets you make changes to one service without impacting another. You can run different php configurations and extensions and versions without worrying about the other services being affected. All of my apps are Wordpress based, so configuration will (or should) be consistent across the board.

我理解运行独立的容器可以对一个服务进行更改,而不会影响到另一个服务。您可以运行不同的php配置、扩展和版本,而不必担心其他服务会受到影响。我所有的应用都是基于Wordpress的,所以配置将(或应该)全面一致。

For now I am leaning toward separation, however I am not sure if this is the best approach.

现在我倾向于分离,但是我不确定这是否是最好的方法。

What do you guys think?

你们怎么想?

3 个解决方案

#1


2  

You should run one service in a container, that's how it's designed. So 1 is out the door.

您应该在容器中运行一个服务,这就是它的设计方式。所以1在门外。

If you look at three, you have a tight coupling between your apps. If you want to migrate to a new php-version for app1, or have a different dependency there, you're in trouble, so that's not a good one.

如果你看一下三个,你的应用程序之间的耦合会很紧密。如果您想为app1迁移到一个新的php版本,或者在那里有一个不同的依赖,那么您就有麻烦了,所以这不是一个好的版本。

The standard is to do 2. A container per service.

标准是做2。一个容器/服务。

#2


0  

The most common pattern that I have seen is a separate container per application. That being said, there also value in having related containers near one another but still distinct, hence the concept of Pods used in Kubernetes.

我见过的最常见的模式是每个应用程序都有一个单独的容器。也就是说,有相关的容器彼此靠近但仍然是不同的,因此库伯内特斯使用的pod概念。

I would recommend one container per application.

我建议每个应用程序使用一个容器。

#3


0  

Per docker documentation multi-service container:

每个docker文档多服务容器:

It is generally recommended that you separate areas of concern by using one service per container. That service may fork into multiple processes (for example, Apache web server starts multiple worker processes). It’s ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

通常建议您使用每个容器使用一个服务来分离关注点。该服务可以派生到多个进程(例如,Apache web服务器启动多个工作进程)。拥有多个进程是可以的,但是为了从Docker中获得最大的好处,避免一个容器负责整个应用程序的多个方面。您可以使用用户定义的网络和共享卷连接多个容器。

Also based on their best practices:

也基于他们的最佳实践:

Each container should have only one concern

每个容器应该只有一个关注点

Decoupling applications into multiple containers makes it much easier to scale horizontally and reuse containers.

将应用程序分离到多个容器中可以更容易地横向扩展和重用容器。

I would suggest using option 2 (separate containers for all services).

我建议使用选项2(所有服务的单独容器)。

#1


2  

You should run one service in a container, that's how it's designed. So 1 is out the door.

您应该在容器中运行一个服务,这就是它的设计方式。所以1在门外。

If you look at three, you have a tight coupling between your apps. If you want to migrate to a new php-version for app1, or have a different dependency there, you're in trouble, so that's not a good one.

如果你看一下三个,你的应用程序之间的耦合会很紧密。如果您想为app1迁移到一个新的php版本,或者在那里有一个不同的依赖,那么您就有麻烦了,所以这不是一个好的版本。

The standard is to do 2. A container per service.

标准是做2。一个容器/服务。

#2


0  

The most common pattern that I have seen is a separate container per application. That being said, there also value in having related containers near one another but still distinct, hence the concept of Pods used in Kubernetes.

我见过的最常见的模式是每个应用程序都有一个单独的容器。也就是说,有相关的容器彼此靠近但仍然是不同的,因此库伯内特斯使用的pod概念。

I would recommend one container per application.

我建议每个应用程序使用一个容器。

#3


0  

Per docker documentation multi-service container:

每个docker文档多服务容器:

It is generally recommended that you separate areas of concern by using one service per container. That service may fork into multiple processes (for example, Apache web server starts multiple worker processes). It’s ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

通常建议您使用每个容器使用一个服务来分离关注点。该服务可以派生到多个进程(例如,Apache web服务器启动多个工作进程)。拥有多个进程是可以的,但是为了从Docker中获得最大的好处,避免一个容器负责整个应用程序的多个方面。您可以使用用户定义的网络和共享卷连接多个容器。

Also based on their best practices:

也基于他们的最佳实践:

Each container should have only one concern

每个容器应该只有一个关注点

Decoupling applications into multiple containers makes it much easier to scale horizontally and reuse containers.

将应用程序分离到多个容器中可以更容易地横向扩展和重用容器。

I would suggest using option 2 (separate containers for all services).

我建议使用选项2(所有服务的单独容器)。