Portainer is one of the most popular and trusted GUI for managing Docker, Swarms, ACIs and Kubernetes. The company boasts on its’ website for having 500K users, and there’s no doubt to the number looking at how easy it makes managing the tools.
This post goes on the very basics of why and how to install and configure Portainer on a Linux Virtual Machine and then use port forwarding to access the popular GUI. For this tutorial, we would focus on the Community Edition (CE) of Portainer (Installation for BE is the same but you need to plug in license during configuration) and configure it to help you manage Docker.
If you’re planning to run Portainer on your server, you need to have Docker Installed and need SSH access to the server. Just as a reminder, we would learn to do all that in lateral sections. I prefer to use VSCode as my preferred tunnelling tool because:
- Tunnelling is smooth and reliable.
- You can use your tunnelling software (VSCode) as an awesome text editor without installing another tool.
- Port Forwarding is Automatic, and you don’t need to configure the ports manually.
So, to summarise, you need these Installed:
- VSCode on your local Machine
- Two extensions Installed on VSCode:
- Docker on the Server (Install Docker Machine from here after SSHing through VSCode)
SSH using VSCode
With the extensions installed, I assume you would have your private keys (the file ending with .pem or .ppk). Now, the process is very simple.
Go and click on the extension and go to configuration by clicking on the gear icon and selecting and opening the
config file auto-generated by the extension.
Then copy the path of your private key and paste that on IdentityFile. The HostName would contain the Public IP of the virtual machine, and Host, User would contain the machine name and Linux username respectively. Please don’t forget to maintain the indentation and populate data starting with input with the necessary details.
Click on the button on the side tab, and press yes twice and a connection to VM will be established.
Now, as you’re in, we need to go and Install Docker if you haven’t already. Read this post about installing Docker and you’re good to go by just installing the Docker Engine. Also, scroll down to Executing the Docker Command Without Sudo (Optional) to use commands without sudo.
To open the Terminal press Ctrl+Shift+`
Check the installation of docker by running
Now, having the prerequisites taken care of, we would install the Portainer server container to manage all the other containers and provide you with the GUI. Here’s how to do this:
Create Docker Volume
Docker Volumes provides you with persistence storage, the type of storage that doesn’t reset if your containers dies. Think of this as installing a game, but it resets all your progress every time you exit the game. How bad does that sound? Docker Volume prevents that by storing your portainer containers data outside the container. Just run the command on your terminal:
docker volume create portainer_data
Install Portainer Container
Now, as you have created the volume for the container let’s install that and run the container with a simple command.
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
You have successfully Installed portainer, and you can see the container running via terminal using the
You can see the container running and if you want to read about the commands more, visit here.
Accessing the GUI: Port Forwarding
We all here are for the GUI and the ease it provides to manage the containers. Now this is the most interesting part for this Installation. A Virtual Server is not your local machine, and you need to forward port to view the GUI on your local machine. VSCode automatically does as soon as it detects but sometimes it misses.
If your VSCode is moody and is in the lateral category, you need to manually click few keys.
Go to Ports menu beside the Terminal.
Click on Forward a Port and then you must enter 9000 as the value and click Enter.
Click on the Globe Icon and you would have your default browser launch. You can visit the front page by going to localhost:9000 on a different browser too.
Accessing the GUI: First Configurations
As this is a beginners tutorial, this is expected to be a first time installation. So, go ahead create a user.
Connecting to the Endpoint
Next steps are to connect portainer to your VMs docker environment so that it can manage that. Click on docker and then connect. You can use it for different options like connection to K8s and other VMs to manage a lot of endpoints together but let’s focus on the most straightforward installation now.
This portainer dashboard view helps you watch all the endpoints if you add more than one. But, as we are using portainer to watch our local docker installation, we can click on the local machine and play with the GUI.
Hope this tutorial would help you manage docker on your server. My use case of portainer ranges from cleaning excessive Images to keep my disk clean and also watching over containers without typing in commands a hundred times in a week.
Feel free to try out Portainer CE and let me know how you used the opensource docker management UI. As always, a great first step to learning more about such platforms is from their direct documentation website.
Read more from us here: