简体   繁体   English

docker-compose 是自愈编排器吗?

[英]is docker-compose a self healing orchestrator?

In kubernetes , if a pod go down for some reason, the admission controller will restart it.kubernetes中,如果某个 pod go 由于某种原因宕机,则接纳 controller 将重新启动它。

We call this mecanism self healing.我们称这种机制为自我修复。

I have never worked with docker-compose , but I wonder: is it the same?我从未与docker-compose合作过,但我想知道:它是一样的吗?

When deployed with docker-compose or now docker compose (with a space) you are deploying to a single node.当使用docker-compose或现在docker compose (带空格)部署时,您将部署到单个节点。 You can define the service to automatically restart with a restart policy that handles a crashing application.您可以使用处理崩溃应用程序的重启策略将服务定义为自动重启。 However, there are a few scenarios where externalities like the network or volumes are not in a good state which I've seen cause the definition to be considered invalid by docker at which point it stops attempting to restart the service.但是,在某些情况下,网络或卷之类的外部因素不在一个好的 state 中,我已经看到导致定义被 docker 视为无效,此时它停止尝试重新启动服务。

There's also Swarm Mode which is an orchestrator like Kubernetes, it can use the docker-compose.yml to define the target state, and it will continue to restart services to recover from an outage, and migrate them to another node when a node in the cluster goes down.还有Swarm Mode,它是一个编排器,比如Kubernetes,它可以使用docker-compose.yml来定义目标state,它会继续迁移到另一个节点,当从一个节点恢复时,它会继续迁移到另一个节点来恢复。下。

  • docker-compose alone is NOT a true container orchestrator. docker-compose 本身并不是真正的容器编排器。
  • It is only a client that allows you to run a service and its dependencies as 1 unit.它只是一个允许您将服务及其依赖项作为 1 个单元运行的客户端。 docker-compose does have a restart policy to restart a container if it crashes or something docker-compose 确实有一个重启策略,可以在容器崩溃或其他情况下重启容器
  • If the node on which the container is running goes down, docker-compose will not be able to restart the container and you will face service interruption如果运行容器的节点宕机,docker-compose将无法重启容器,将面临服务中断
  • Docker Swarm and Kubernetes are Servers and not just the clients so they are more comprehensive orchestrators Docker Swarm 和 Kubernetes 是服务器,而不仅仅是客户端,因此它们是更全面的协调器

To achieve self-healing in the context of docker, one can create services just like in Kubernetes.要在 docker 的上下文中实现自愈,可以像在 Kubernetes 中一样创建服务。 But services can only be created when using Docker in swarm mode.但是只有在swarm模式下使用Docker时才能创建服务。

To enable swarm, use: docker swarm init .要启用 swarm,请使用: docker swarm init
And then go on to create a service like:然后 go 上创建一个服务,如:
docker service create [service-name] [--options [values]...]

If you want to utilize docker-compose to create a service, here's how you can do that for a Postgres database:如果您想利用 docker-compose 创建服务,以下是您可以为 Postgres 数据库执行此操作的方法:

version: "3.1"

services:
  psql:
    image: postgres
    secrets:
    - psql_user
    - psql_password
    environment:
      POSTGRES_USER_FILE: /run/secrets/psql_user
      POSTGRES_PSWD_FILE: /run/secrets/psql_pass

secrets:
  psql_user:
    file: ./psql_user.txt
  psql_password:
    file: ./psql_pass.txt

Lastly, go on and use docker-compose up in the same directory where docker-compose.yaml is present and it will get your psql service up and running.最后,打开 go 并在 docker-compose.Z6EEDC03A68A69933C763E674F2 运行的同一目录中使用docker-compose up并运行它。

To elaborate a bit, docker-compose isn't an orchestrator per se.详细地说,docker-compose 本身并不是一个编排器。 docker-compose is a mechanism to start or stop multiple containers simultaneously using a single and single command. docker-compose 是一种使用单个命令同时启动或停止多个容器的机制。

Also, it had to be stated that docker-compose is a testing utility and is not meant to be used in production.此外,必须声明 docker-compose 是一个测试实用程序,并不打算用于生产。 For production use, take a look at stack .对于生产用途,请查看stack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM