Docker Stack: Simplifying Multi-Container Applications on Cluster

Docker Stack: Simplifying Multi-Container Applications on Cluster

INTRODUCTION:

As a DevOps engineer, I’ve worked with Docker for years, and one of the most powerful tools in the Docker ecosystem is Docker Stack. If you’re familiar with Docker Compose, Docker Stack takes it a step further by enabling you to deploy and manage multi-container applications in a Swarm mode cluster. In this blog, I’ll explain what Docker Stack is, its anatomy, and how to use it with real-world examples.

What is Docker Stack?

Docker Stack is a command-line tool that allows you to deploy and manage a group of services (containers) defined in a Docker Compose file on a Docker Swarm cluster. It’s perfect for deploying production-grade applications that require scalability, high availability, and easy management.

Think of Docker Stack as a way to deploy your entire application stack (e.g., web server, database, cache, etc.) with a single command. It’s built on top of Docker Swarm, which provides orchestration and clustering capabilities.

Why Use Docker Stack?

  1. Scalability: Easily scale services up or down.

  2. High Availability: Docker Swarm ensures your services are always running, even if a node fails.

  3. Declarative Configuration: Define your entire stack in a single YAML file.

  4. Simplified Management: Deploy, update, and remove stacks with simple commands.


Write a compose file to deploy on swarm

compose.yml

---
version: "3"
services:
  movie:
    container_name: movie-container
    build: ./movie-tickets
    ports:
      - "8081:80"

  bus:
    container_name: bus-container
    build: ./bus-tickets
    ports:
      - "8082:80"

  train:
    container_name: train-container
    build: ./train-tickets
    ports:
      - "8083:80"

deploy it on stack

docker stack deploy mustafa --compose-file=compose.yml

to see the list of stacks:

docker stack ls

to see the list of services

docker service ls

to see the list of containers

docker service ps service_name

Scale a Service:

docker service scale service_name=5

Conclusion

Docker Stack is a powerful tool for deploying and managing multi-container applications in a Docker Swarm cluster. By defining your services in a single YAML file, you can easily deploy, scale, and manage your application stack. Whether you’re running a small web app or a large-scale microservices architecture, Docker Stack simplifies the process and ensures high availability.

I hope this blog post has given you a clear understanding of Docker Stack and how to use it in real-world scenarios. If you have any questions or want to share your experiences, feel free to leave a comment below!

Give me your heart 💖

If you found this blog helpful for your interviews or in learning Docker troubleshooting, please hit a heart for 10 times and drop a comment! Your support motivates me to create more content on DevOps and related topics. ❤️

If you'd like to connect or discuss more on this topic, feel free to reach out on LinkedIn.
Linkedin: linkedin.com/in/musta-shaik