An open API service indexing awesome lists of open source software.

https://github.com/dhanikaa/docker-swarm

A demonstration on how to set up and manage services in a Docker Swarm cluster. It includes examples of Dockerfiles, a custom Nginx configuration, and a docker-compose.yml file for deploying and scaling services in Swarm, with a focus on high availability and fault tolerance. Perfect for learning Docker Swarm orchestration.
https://github.com/dhanikaa/docker-swarm

docker docker-compose docker-swarm

Last synced: 2 months ago
JSON representation

A demonstration on how to set up and manage services in a Docker Swarm cluster. It includes examples of Dockerfiles, a custom Nginx configuration, and a docker-compose.yml file for deploying and scaling services in Swarm, with a focus on high availability and fault tolerance. Perfect for learning Docker Swarm orchestration.

Awesome Lists containing this project

README

          

# Docker Swarm: Orchestration for Docker

## Overview
Docker Swarm is Docker's native clustering and orchestration solution. It turns a pool of Docker hosts into a single, virtual host. This makes it easier to manage multi-container applications and scale them horizontally across a cluster of machines.

This repository demonstrates how to set up and use Docker Swarm, deploy services, and scale them efficiently.

## What is Docker Swarm?
Docker Swarm is Docker's native clustering and orchestration tool. It allows you to manage a group of Docker nodes as a single virtual host. In a Swarm setup, containers are distributed across nodes based on the available resources and scaling requirements. Swarm provides high availability and load balancing for services running in containers.

### Key Features:
- **Clustering:** Organize multiple Docker hosts into a single Swarm.
- **Service Discovery:** Swarm provides internal DNS for service discovery.
- **Load Balancing:** Swarm load-balances traffic between services running in containers.
- **Scaling:** Easily scale services up or down.
- **High Availability:** If a container fails, Swarm will restart it on another node.

## Setting Up Docker Swarm Cluster

To set up a Docker Swarm cluster, follow these steps:

1. **Initialize the Swarm on the Manager Node:**
On the manager node, run the following command:
```bash
docker swarm init --advertise-addr
```

2. **Join Worker Nodes to the Swarm Cluster:**
Once the Swarm is initialized, you’ll be provided with a command to join worker nodes to the cluster. Run the command on the worker node:
```bash
docker swarm join --token :2377
```

3. **Verify the Cluster:**
To ensure that your nodes are part of the cluster, use the following command on the manager node:
```bash
docker node ls
```

## Deploying Services in Docker Swarm

Docker Swarm allows you to deploy and manage services across multiple containers and nodes. A service in Swarm is simply a container or a group of containers running a specific application.

To deploy a service in Docker Swarm:

1. **Create and Deploy the Service:**
```bash
docker service create --name my-web-service --replicas 3 -p 80:80 nginx
```
This will create a service named `my-web-service`, running three replicas of an NGINX container, and exposing port 80.

2. **Verify the Service:**
```bash
docker service ls
```

3. **Inspect the Service:**
To get detailed information about the service:
```bash
docker service ps my-web-service
```

## Scaling Services in Docker Swarm

One of the key benefits of Docker Swarm is the ability to easily scale services up or down.

1. **Scale a Service:**
To increase the number of replicas for a service, use the following command:
```bash
docker service scale my-web-service=5
```
This will scale the `my-web-service` to 5 replicas.

2. **Verify the Scale:**
```bash
docker service ps my-web-service
```

3. **Remove a Service:**
If you no longer need a service, remove it with the following command:
```bash
docker service rm my-web-service
```

## Conclusion
Docker Swarm provides a robust and easy-to-use solution for orchestrating containers across multiple hosts. It simplifies the process of scaling, load balancing, and managing services in production environments. With its built-in features, Docker Swarm allows developers to deploy, scale, and manage their applications efficiently with minimal overhead.

## Additional Resources
- [Docker Swarm Documentation](https://docs.docker.com/engine/swarm/)
- [Docker Compose with Swarm](https://docs.docker.com/compose/)