Using and managing docker with portainer
Taking the pain out of command line docker
Last updated
Was this helpful?
Taking the pain out of command line docker
Last updated
Was this helpful?
If you're inexperienced with managing *nix systems, or like me you use docker so infrequently that you find yourself having to constantly reach for the documentation, portainer can really help to keep you productive by providing a more intuitive UI than wading through pages of terminal command outputs.
This guide will show how to create a docker swarm environment with two linux hosts, for this guide I will be using two Debian 10 virtual machines.
The purpose of showing how to use docker swarm is to provide an understanding of how you can centrally manage multiple low-resource docker hosts (such as Raspberry Pis for example) allowing you to quickly scale your infrastructure outwards should you eventually be running so many containers that you've outgrown your single host.
One thing to note about using docker on Debian 10 is that at the time of writing, the default docker package (docker.io), whilst supporting docker swarm mode, has a bug due to an included package dependency which is not re-entrant. This means that the docker host service itself can crash. For more info see the , and the the bug on the dependency.
To get a stable docker swarm, I would recommend installing docker-ce instead. Instructions for how to do this can be found on the .
For my example I am using a wildcard certificate for my domain thecko.co.uk, this certificate will be used by traefik as the default TLS certificate to be used. A further blog post will come at a later date showing how to to configure the traefik service for portainer to use letsencrypt to dynamically retrieve and manage certificate for exposed service.
In my example I have create a folder called certificates, in which I have my .crt and .key files for my domain named cert.crt and cert.key respectively.
This folder also contains a file certificates.toml which specifies the certificate should be used as the default. The contents are as follows
In the same folder which contains your certificates folder, create a file called portainer-agent-stack.yml and copy and paste the following.
This example is predicated on having a wildcard A record on your domain which points to the same address of the your main docker host.
Due to this configuration being setup to use docker swarm mode, you will need to first execute some commands to setup the docker environment. The shell script below will do this work for you. Copy the contents in to a file name of your choosing. For my example, I simply called it startportainer.sh
When executing the shell script, you will be given information as to how to join a new worker node to the swarm. Do not worry if you accidentally close the terminal and lose that information, you can always find it again by running the command
Once you have started the initial service, navigate to the host you specified in the portainer-agent-stack.yml for the portainer service. In my case, it's https://portainer.thecko.co.uk
You will need to set up the name and password for your initial administrator user.
Once you have logged in you will see a list of endpoints.
We will only using the primary endpoint here, click on the endpoint and you will be shown an overview of the stacks, services, containers, volumes, and networks which now exist on your docker host.
To start with, click the link near the top of this page titled "Go to cluster visualizer"
This will now show you that you have one node in your docker swarm cluster. It should be running three services, agent, portainer, and traefik.
Now the first docker host is setup we can add our extra worker node to the swarm. As mentioned previously, if you didn't keep a note of the command you were given to join a worker node to the swarm during the initial setup, you can run the following command on your first docker host to retrieve it
Run the "docker swarm join" command on your second host.
Once you have done this, go back to your web browser with the cluster visualization page still open, and you should see that you now have 2 nodes in your swarm cluster.
The contents of the file below are slightly modified from the information provided on the