Docker Swarm is Awesome with Portainer
I have been revisiting how I have been running containers in my home lab. While Kubernetes is awesome, and I continue to run various deployments of it in the home lab, for the most part, most of my “production” containers have been running on standalone hosts. However, this brings challenges when it comes to even simple things like patching your container hosts. I want to go over a new setup in my environment that I am very happy with so far, and by using a well-known Docker management tool, Portainer, Docker Swarm is awesome.
Table of contents
- What is Docker Swarm?
- Quick comparison of Docker Swarm vs Kubernetes
- What is Portainer?
- Docker Swarm is a great middle ground
- How hard is it to install a Docker Swarm cluster?
- Docker Swarm with Portainer feels as slick as using vSphere client
- Management activities in Docker Swarm
- Security configuration and advanced tools
- Wrapping up
What is Docker Swarm?
Docker Swarm is a native orchestration tool from Docker that allows you to run Docker containers with high-availability and many of the features that you need when running containers in production. However, over the past several years it has been overshadowed by Kubernetes.
Don’t get me wrong, Kubernetes is a great technology for those who need what it can provide. However, I find that for many environments, including production environments and lab environments, like home labs, what most need and want is just a simple way to run containers with high availability.
Quick comparison of Docker Swarm vs Kubernetes
Note the following areas where Docker Swarm will fall short of Kubernetes:
- Advanced networking
- Auto-scaling
- Self-healing
- Complex workloads
Note areas where Docker Swarm will excel when compared to Kubernetes:
- Ease of setup
- Much simpler management
- Integration with Docker
- Speed of deployment
- Native Docker networking and volumes
- Lower learning curve
- Single CLI tool with Docker CLI
These are just a few that I can think of.
What is Portainer?
In my opinion, Portainer is the single most important Docker management tool that an administrator can know and use. It provides GUI management and tools for your Docker, Nomad, Kubernetes, and standalone Docker hosts. Once you deploy Portainer and start using it for daily administration, you will ask yourself why you didn’t start using it earlier.
You can learn more about and download Portainer here: Kubernetes and Docker Container Management Software (portainer.io).
Portainer adds the functionality and management experience that many long for when they start working with containers from the command line. Don’t get me wrong, I started life as a network administrator, so I am definitely at home at the command line working on switches, routers, and other gear. However, once you get past the initial charm of the command line, this becomes a grind to work with day in and day out, especially when spinning up and working with containers.
Portainer agent
Portainer manages your Docker swarm hosts using the Portainer agent. Once I had my Docker Swarm hosts up and running with Docker installed, I simply installed the Portainer agent on each host. This allows your Portainer server instance to connect and manage the hosts where the agent is installed.
Docker Swarm is a great middle ground
Many have discounted Docker Swarm as “dead” or “nobody is using it” type of technology. But this is just not true. And, unfortunately, this mindset often prevents shops from using it when it would be a great fit for what they want to do.
I see the progression of Docker/container tools as the following:
- Standalone hosts – Great for getting started with containers and the easiest option. This can even be ok for production if you understand the limitations, risks, etc.
- Docker Swarm – A great “middle ground” between standalone hosts and Kubernetes. Often, organizations don’t need Kubernetes, and the complexity and management of the solution defeat the benefits that it brings. Docker Swarm gives you high availability for your containers and provides most of what I think SMB and small to mid-sized businesses may actually need.
- Kubernetes – The de-facto cloud-native solution that allows running containers for production and cloud environments. However, with Kubernetes comes a lot of complexity that many environments may not want or need.
Long story short, don’t discount Docker Swarm as a great option that might solve the use case you are looking for without the complexity of Kubernetes but much greater high availability and orchestration features than standalone Docker hosts.
How hard is it to install a Docker Swarm cluster?
Not hard at all, basically a single command on your initial master node, and then running the join command on your other nodes:
docker swarm init --advertise-addr <master address>
Next, joining your other nodes is just simply running the join command that the Docker master gives you in the image above. Just copy and paste the command from master to your workers
You can also promote your workers to masters very easily if you want to have a multi-master configuration.
docker node promote <ip address>
Why Run Docker Swarm instead of standalone hosts or Kubernetes?
Well, as we mentioned above, Swarm is a great middle ground and I think it will do most of what ones are looking to do when they are getting into container orchestration and simply want to run highly available containers. If you don’t want the complexity of Kubernetes but you need something more than a standalone Docker host, Swarm is that “something” in my opinion.
Also, for me, there are just some containers that are simply not made to run inside Kubernetes. I can think of solutions like home assistant that many have issues with running inside of Kubernetes. Docker Swarm gives you the native seamless docker container experience and just adds the orchestration layer on top.
Also, if you want to have better visibility on the overall landscape of your container infrastructure, running multiple standalone hosts becomes difficult since you have to manage these individually. Portainer makes this a lot easier, but still it can be cumbersome.
With Docker Swarm, your containers are presented as a logical aggregate, so you can see and have visibility on everything running via the Docker services.
Docker Swarm with Portainer feels as slick as using vSphere client
When you combine Docker Swarm hosts with Portainer, the experience is absolutely fantastic. Portainer’s interface and functionality are extremely good and give you all the point-and-click functionality that you want/need when working with your Docker Swarm hosts.
It makes managing your Docker Swarm services extremely easy and allows having visibility to all the containers running across all your hosts in the Docker Swarm cluster.
One of the tools I especially love is the Cluster visualizer. This tool, which is built into Portainer, allows you to visually see your Swarm cluster hosts and the containers running on each host.
With the cluster visualizer you can view only running tasks or view all tasks, even those that are not running, failed, rejected, etc.
Management activities in Docker Swarm
Also, Portainer makes day-to-day management activities in Docker Swarm super easy. Things like updating your stacks and services are easy with the tool:
Below, you can see that viewing logs in Portainer is really easy as well, making it much simpler to troubleshoot and quickly get to root cause of issues with your containers.
Activities like draining and pausing nodes is a simple drop down box in the Portainer GUI for your Docker Swarm nodes.
Security configuration and advanced tools
One of the great things that I think Portainer gives visibility to and allows admins to do is implement security best practices in container management. In the settings for your host, you can, with a simple toggle, implement things like disabling bind mounts for non-admins, disabling privileged mode for non-admins, disabling stacks, disabling device mappings, and many others.
Wrapping up
Stay tuned as I will create a detailed blog on getting Docker Swarm up and running with GlusterFS and Portainer so you guys can see how I have configured by setup. All in all, I am very happy with how things are going with the Swarm cluster in the lab running critical services that I want to be able to have high availability on but not have all the complexity with Kubernetes. Portainer is like the cherry on top that makes this solution just fantastic.