I will install and set up Docker Swarm with a minimum of three Docker containers: one manager container and two worker containers. I will open some ports for communication, and deploy services using the docker stack commands.
My previous post "in this 8-part mini-series" covered installing Portainer in a Docker container. My actual previous post, however, covered how to deploy multiple Docker containers. Why do I need multiple containers? Because a prerequisite for this lab is a minimum of three (3) Docker containers: I've named my containers
Docker2, and (to absolutely no one's surprise)
The purpose of this post is to show how to install Docker Swarm across, at least, three Docker containers.
The Big Picture.
The big idea is to set up an environment where I can develop my Docker Swarm management skills. From what I learned (online), Docker Swarm is easier to grasp than K3s or K8s. The big picture I'm looking toward combines Docker Swarm with Nginx reverse proxy and Nginx load balancing.
Setting Up a Docker Swarm.
Here are the steps I use to set up a Docker swarm:
I need at least 3 containers running Docker - The
Dockercontainer will run the Docker manager while the
Docker3containers will run the Docker workers. The
Dockercontainer must be able to communicate with the other containers over the network.
I install Docker within all of the containers.
From the terminal (
T) that is connected to the
Dockercontainer, I initialize the swarm mode:
sudo docker swarm init --advertise-addr 192.168.?.?
NOTE 1: This will make Docker (inside the Docker container) the host (or swarm manager).
NOTE 2: I replace the ? above with the IP address for the
Dockercontainer. This is the experimental part. If this does not work, then I will need to figure out how to reference the IP address of the Docker instance instead.
- I issue the following UFW commands in all the containers:
sudo ufw allow 2377/tcp sudo ufw allow 2377/udp sudo ufw allow 2376/tcp sudo ufw allow 7946/tcp sudo ufw allow 7946/udp sudo ufw allow 4789/udp
2377 TCP for communication between manager nodes, 7946 TCP/UDP for node discovery, and 4789 UDP for overlay network traffic.
The other two containers can join the swarm as workers by running the command given in the output of the
docker swarm initcommand on the
Dockerterminal. It will be something like:
sudo docker swarm join --token <token> <manager IP>:2377
Dockerterminal, I run
docker node lsto view the swarm:
- I can now deploy services to the swarm using
docker stack deploycommands. The services will be scheduled across the manager and worker nodes.
This covers the basic steps to setting up a Docker swarm.
I demonstrated the process of setting up a Docker Swarm with Docker containers. By using a minimum of three containers, I was able to create a swarm of one manager node and two worker nodes. This setup allows for the efficient deployment and management of services across the swarm, providing a powerful tool for container orchestration. Docker Swarm will be a valuable addition to my toolkit as I continue to expand the capabilities of my
If you've been linearly following this blog, then you'll notice a higgledy-piggledy order to these articles. I've touched on a number of OpTec services and now I need a mind map to guide me through my own thoughts. I'm ready to search for an optimal layout for these servers. Something like a high availability, load-balanced version of the following might work as a starting point:
Until next time: Be safe, be kind, be awesome.