VOOZH about

URL: https://thenewstack.io/tutorial-manage-docker-swarm-with-portainer/

⇱ Tutorial: Manage Docker Swarm with Portainer - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-04-23 07:00:16
Tutorial: Manage Docker Swarm with Portainer
tutorial,
Cloud Native Ecosystem / Containers

Tutorial: Manage Docker Swarm with Portainer

Manage Docker Swarm with Portainer.
Apr 23rd, 2022 7:00am by Jack Wallen
👁 Featued image for: Tutorial: Manage Docker Swarm with Portainer

The Docker Swarm container orchestration engine is a great way to take advantage of a cluster for your container deployments. Although it might not be nearly as popular as Kubernetes, it’s still a great option if you’re looking for features like:

  • Cluster management integrated with Docker Engine
  • Decentralized design
  • A declarative service model
  • Scaling container deployments
  • Desired state reconciliation
  • Multi-host networking
  • Service discovery
  • Load balancing
  • Secure deployments
  • Rolling updates

And given how much easier Docker Swarm is to use (than Kubernetes), it’s a great way to introduce containers into your development lifecycle mix.

But even though Docker Swarm is quite easy to manage, there’s an even easier way… thanks to Portainer container management system. Once you have your Docker Swarm up and running, you can deploy Portainer and it will automatically pick up your controller and all of your nodes.

I want to walk you through the process of Deploying Docker Swarm and adding Portainer into the mix. Once you have this up and running, you’ll find it exponentially easier to manage your clustered Docker servers and the containers/services you’ve deployed.

The first thing we need to do, however, is spin up a Docker Swarm. I’ll be demonstrating this with three instances of Ubuntu Server 20.04. You can deploy this setup on any Linux machine, but you’ll need to modify the installation process to fit your distribution of choice.

Let’s get down to work.

Deploying Docker Swarm

Log into your first instance of Ubuntu and install the necessary dependencies with the command:

sudo apt-get install ca-certificates curl gnupg lsb-release -y

Once that installation completes, add the official Docker GPG key with the command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, we can add the stable Docker repository with the command:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update apt with the command:

sudo apt-get update

Install Docker Engine (community edition) with:

sudo apt-get install docker-ce docker-ce-cli containerd.io -y

When the installation completes, you’ll want to start and enable the Docker service with:

sudo systemctl enable --now docker

To be able to issue the docker command without sudo privileges (which can be a security issue), add your user to the Docker group with:

sudo usermod -aG docker $USER

Log out and log back in for the changes to take effect (or just issue the command newgrp docker and you’re good to go).

It’s important that you then repeat the above steps on every Docker node you plan to join to the Swarm.

Initializing the Swarm and Joining Nodes

Go back to the controller (the first machine you installed Docker on) and discover the IP address of that machine with:

ip a

You can now initialize the Swarm with the command:

docker swarm init --advertise-addr SERVER

Where SERVER is the IP address for the Docker Controller.

When that command completes, it’ll print out a join command that looks like this:

docker swarm join --token TOKEN 192.168.1.13:2377

Where TOKEN is a long string of random characters. Copy that command and run it on every node you want to join the swarm. Once you’ve joined all the nodes, go back to the Controller and issue the command:

docker info

You should see a line in the output that looks like:

Nodes: 3

All three nodes have successfully joined the Swarm.

Deploying Portainer

The next trick is to deploy Portainer with the command (run on the controller):

docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

Give the container a moment to spin up and then point a web browser to http://SERVER:9443 (Where SERVER is the IP address of the Controller). Create an admin user and log in. Because Portainer has been deployed to a controller in a Swarm, you’ll see an entry for Swarm in the left sidebar (Figure 1).

👁 : Portainer adds a Swarm entry when it's part of a cluster.

Figure 1: Portainer adds a Swarm entry when it’s part of a cluster.

Now the fun begins.

Let’s deploy a service to our Swarm. Click Services in the left sidebar and then click Add service. In the resulting window (Figure 2), you should see a Replicas entry.

👁 Replica entry

Figure 2: Creating a new service via Portainer.

Because we’re working with a Swarm that involves three total nodes, we can bump the replicas entry up to three, so the service we’re deploying will replicate to every node on the swarm (for high availability and failover).

Let’s deploy an NGINX service to our Swarm. Give the service a name and then type nginx:latest in the Image field. Bump Replicas up to three and click Create the service (Figure 3).

👁 Deploying a service to Docker Swarm

Figure 3: A very basic service to be deployed to our Docker Swarm.

Once the service has successfully deployed to the Swarm, it’ll be listed in the Service list (Figure 4).

👁 Node replication

Figure 4: Our tnsDockerTest service has replicated to all nodes in the Swarm.

Another cool trick you can do via Portainer is to scale the service up and down. If you click the Scale button in the listing, the field will change (Figure 5) such that you can scale the service up or down as needed.

👁 Scaling a service with Portainer.

Figure 5: Scaling a service up or down is very easy through Portainer.

And that’s how easy it is to manage your Docker Swarm with the help of Portainer. If you have any intention of working with Docker Swarm for your business, I highly recommend giving this user-friendly, web-based GUI a try. You’ll find your work to be more productive, efficient, and reliable.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.