Deploy Containers

To deploy the above file in the docker swarm you need to use the below command:

docker stack deploy my-stack -c docker-compose.yml

Now open the docker desktop to see the 3 running containers.

To check whether container is properly running the nginx image or not, open the web browser and paste the below url:

http://localhost:80

You can also see the list of services currently running using the below command:

docker service ls

If any node fails and one of the above three containers stops, the docker swarm will automatically restart it on some other healthy worker node.

How to Use Docker For Fault Tolerance with Docker Replicas?

Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. A cluster of docker engines is called a swarm. Docker Swarm is a cluster management and orchestration feature embedded in the Docker Engine.

Similar Reads

Docker Replicas

Docker replicas refer to running multiple instances of a docker container to ensure high availability, scalability, and load balancing. Docker replicas allow you to scale your application stack by creating multiple instances of a service....

Docker Swarm

Docker swarm allows the running of a docker container across a cluster of nodes and manages those containers as a single unit....

Docker Service

The main building block of the docker swarm is a service. A docker swarm service is a group of Docker containers managed together. In a service, you specify the image to be used and the commands to run inside the running container. You can also specify other info such as the number of replicas of an image to run, and the port to which the service will be available outside the swarm. Docker swarm breaks the service into one or more tasks based on the replicas value. One task in the docker swarm corresponds to exactly one running container....

Docker Compose

Docker compose is a tool for defining and running multi-container docker applications. In compose you create a YAML file defining all the services that are needed in your application, along with the image, ports, environment variables, network, and volumes associated with each service. For example, you might describe an application comprised of a web front-end service with message queueing services and a database backend....

Enable Docker Swarm

To enable docker swarm in your machine to run multiple instances of container for fault tolerance you need to run the following command:...

YAML File creation

Below is a simple docker-compose.yml file:...

Deploy Containers

...

Scale

To deploy the above file in the docker swarm you need to use the below command:...

FAQs on Docker Swarm

Now if you want to create more containers you can use the below command:...