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 ?
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 ?
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 file 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.
When deployed with
docker-compose
or nowdocker 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.