Using Portainer.io to build and manage your Docker swarm

 •  Filed under portainer.io, build, manage, docker, swarm

Are you planning on deploying a Docker swarm anytime soon? Just rethink about how you want to manage your Docker compute hosts. Do you want to go with the CLI way of doing things, or are you most likely preferring a GUI-based frontend to manage your Docker swarm? Personally I'm a fan of doing all the things over a CLI interface, but hey: GUI-managed solutions can be good if they are done right.

So, let's get straight into talking about what Portainer.io can do for you and your (future) Docker environment: most of the things that you would usually do in the Docker CLI interface are made into a sleek-looking graphical interface with Portainer.

Setting up a basic Docker swarm with two compute nodes

Imagine having three servers for your Docker setup:

  • A management server to manage your Docker swarm, while at the same time being equipped with Portainer.io
  • Two compute servers which both function as a member of the Docker swarm

These are the IP addresses of the 3 machines

  • Docker Manager: 10.131.38.69
  • Docker Compute 01: 10.131.40.233
  • Docker Compute 02: 10.131.17.82

On the 'Docker Manager' machine, you execute the following command to initialise a new Docker swarm:

docker swarm init --advertise-addr 10.131.38.69  

This command also returns what you need to know to make compute nodes join your Docker swarm:

Docker Swarm Init

Once you have all your member servers joined into your swarm you can install Portainer.io on your Docker management server with this command:

docker service create --name portainerio -p 9000:9000 --constraint 'node.role == manager' --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock portainer/portainer -H unix:///var/run/docker.sock  

You are now running a Portainer.io instance on port 9000, great! Open your webbrowser and navigate to the web interface, fill in a password and login with the password that you just set.

Docker swarm in portainer.io

Boom! It works and shows you all the worker machines inside the web panel. Now it's all up to you what you are going to build and/or deploy. I hope this article was informative for you, enjoy the freedom of containers!