Technical skill

Docker orchestration

Subject: .../LINUX

Keep containerized services running

An application can use several parts: a web server, a database, and a worker, for example. A container is an isolated running instance of an image. An image packages a program with the files it needs to run. Orchestration is software that decides where containers should run and helps keep the requested number running across computers. You describe the result you want, such as three copies of a web service; the orchestrator compares that desired state with what is running and works to close the gap.

On a Docker Engine that has already joined a Swarm cluster, these commands start three Nginx service tasks and inspect them:

docker service create --name web-demo --replicas 3 --publish 8080:80 nginx:alpine
docker service ls
docker service ps web-demo

The first line asks Swarm to run three copies from the nginx:alpine image and publish port 8080 on the cluster to port 80 in the container. An image is the packaged starting point for a container. docker service ls shows requested and current replica counts; a replica is one running copy. docker service ps shows the tasks that represent those copies, their assigned machines, and any errors. Change the request to four copies with docker service scale web-demo=4, then check the tasks again.

Choose the tool for the job

Docker Compose describes related services, networks, and volumes in a Compose file and runs them together. A volume stores data separately from a container's writable layer. Compose can be used in development and other environments, but a Compose file alone does not provide a multi-machine cluster scheduler or control plane.

Docker Swarm mode is built into Docker Engine and groups Docker hosts into a cluster. A host in the cluster is called a node. A Swarm service describes what should run, including its image, number of replicas, network and port settings, resource limits, placement preferences, and update behavior. Manager nodes schedule tasks onto nodes and try to maintain the requested state. A task is a unit of work that runs a container.

Kubernetes is another orchestrator, with its own API objects and controllers. Its resources and Swarm concepts are not interchangeable. Use Compose when one machine can manage the application. A cluster orchestrator is useful when work must be scheduled, restarted, scaled, or updated across machines.

Plan for failures and stored data

The requested state may remain unmet if an image cannot be pulled, the machines lack resources, or no available node matches placement rules. Swarm reports task state and may retry or reschedule work according to its rules. It cannot repair a broken image or a missing application dependency.

Several replicas add redundancy only if the application and its data model support multiple copies. If a container writes important data only to its local writable filesystem, moving its task to another node does not move that data. Persistent volumes, backups and recovery, application-level replication, and a stable service identity need their own design.

A running container is not necessarily a healthy application. A process-level health check may not test dependent services or important operations. Choose checks and update behavior around the failures that matter, and monitor the application alongside the orchestrator's status. Keep the image, configuration, network, and persistent data plan explicit.

Interactive exercises

Materials

Skillsets
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful