简体   繁体   中英

is docker-compose a self healing orchestrator?

In kubernetes , if a pod go down for some reason, the admission controller will restart it.

We call this mecanism self healing.

I have never worked with docker-compose , but I wonder: is it the same?

When deployed with docker-compose or now docker compose (with a space) you are deploying to a single node. 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.

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.

  • docker-compose alone is NOT a true container orchestrator.
  • It is only a client that allows you to run a service and its dependencies as 1 unit. docker-compose does have a restart policy to restart a container if it crashes or something
  • 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 Swarm and Kubernetes are Servers and not just the clients so they are more comprehensive orchestrators

To achieve self-healing in the context of docker, one can create services just like in Kubernetes. But services can only be created when using Docker in swarm mode.

To enable swarm, use: docker swarm init .
And then go on to create a service like:
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:

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.

To elaborate a bit, docker-compose isn't an orchestrator per se. docker-compose is a mechanism to start or stop multiple containers simultaneously using a single and single command.

Also, it had to be stated that docker-compose is a testing utility and is not meant to be used in production. For production use, take a look at stack .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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