
Having Docker on a Raspberry Pi is awesome because you can run multiple containers, web services, and websites without any hassle. Keeping track of all these different containers, images, volumes and networks can be quite hard when you don't have a visual interface to work with.
This is where Portainer comes into the picture! Portainer is a free container-management system that allows you to manage, start and stop containers, volumes, networks, and much more in a web interface instead of in the console.
In this tutorial, we will be installing Portainer on your Raspberry Pi, so that you easily can manage your Docker containers in one place. Portainer will be running through Docker, so if you haven't already installed Docker, please follow our guide here: How to install Docker on a Raspberry Pi 4.
Install Portainer Web UI on a Raspberry Pi
To be able to go through this tutorial you are required to have a Raspberry Pi running the Raspbian OS and have an internet connection. It should also have Docker installed since Portainer will be using Docker to run. If you already have all these steps in order, please start with step one to begin the installation.
Before you begin
Before we begin the installation we should make sure that the Raspberry Pi is updated and upgraded to the newest version. So to begin we start by using SSH to connect to our Raspberry Pi. Once we have established a connection to our Raspberry Pi we type the following in the console to update the packages and then afterward upgrade the device.
sudo apt-get update && sudo apt-get upgrade
Step 1: Install Portainer using Docker
The first step is to install Portainer using Docker and to do that, we need to download the latest Portainer image from Docker Hub. You can copy/paste the line below to download the latest ARM image that fits your Raspberry Pi.
sudo docker pull portainer/portainer-ce:latest
Once the image has been downloaded to your Raspberry Pi you can copy/paste the line below to start it using Docker.
sudo docker run -d -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
The line above is telling Docker to run the image as a container, and that it should be using port 9443. We are also telling Docker what to name this container and that we want it to automatically restart if something goes wrong. At the end of the line, we are telling it where to store the data and which image it should be using.
Once Docker is done spinning up your new Portainer web interface, you should be able to access it by going to [Raspberry-Pi-Ip]:9443. In our case that would be 192.168.100.101:9443.
Step 2: Initial Portainer setup/basic usage
The first time you access Portainer you will have to go through the initial setup steps, but don't worry they are very easy. The first step is to create a Portainer user that will be administrating the different containers you are running. Please write down the username and password since this will be the administrative user.
After creating the administrator account you have to declare where your Docker container will be running so that Portainer knows which ones to show you. You will get 3 options which are "Docker", "Kubernetes" and "Agent". In this section, you should choose "Docker" since you will be running your images locally on your Raspberry Pi and it will be Docker that manages them.
After going through the initial setup you will be directed to the web interface where you can manage your Docker containers. If you in the Dashboard click on the endpoint called "local" you will be able to see your local Docker containers. There should already be one since Portainer is a Docker container.
Start your first docker container in Portainer
Now that we have Portainer installed on our Raspberry Pi it is time to start our first container. Nothing fancy, but just a simple MongoDB database to check that our system is working as it should. We can do it in a few different ways, but the one I would like to show you is by using the Stacks option which allows us to set up a container by using docker-compose.
By using docker-compose we can specify more details in a structured and easy-to-read way, compared to the CLI. So click the Stacks link in the menu to the left and go to the web editor at the bottom of the page. In the web editor, you will be pasting the following code.
version: '3' services: db: container_name: mongo image: mongo:4.4.5-bionic volumes: - dbdata:/data/db restart: unless-stopped volumes: dbdata: driver: local driver_opts: type: none device: / o: bind
Once you have pasted the code into your web editor you can click on Deploy the stack at the bottom of the page. This will then start the process of running on your first MongoDB database directly from Docker on your Raspberry Pi. If you go back to the Containers page, then you can see when the database is done and ready to be used. If no errors show up and the status shows that the container is running, then everything should be fine and you can take down the container again (Unless you want to continue with MongoDB).
Use the prebuilt app templates in Portainer
Portainer is an amazing tool and to make it even better, then you can find app templates that are free to use and the list is long. You can find everything from databases and docker image registry to web servers, CMS systems, and backup solutions. All that it takes for you to set up is 2 clicks.
To set up your own app from the template list you can go to the App template page in the menu to the left. On the page, you will find a long list of services and if you click on a template you can choose Deploys the container.
How to edit running containers in Portainer
A cool feature in Portainer is that you can edit running containers. This means you can change options such as the restart policy without having to actually stop the container and start up a new one with the changed policy.
To change information in a running container you go to the Container page in the menu to the left. On the Containers page, you will see a list of all your containers both running and stopped and if you click on one of them you will be brought to the settings page. On the settings page, you can change the information of the container, see useful information, change the restart policy, access the logs, and much more.
Wrapping up
By this time you should have Portainer installed on your Raspberry Pi running Docker. It is a smart little piece of software that makes managing Docker containers easier and we hope that it will bring as much joy to you as it has brought us.
Lastly, if you have experienced any problems installing Portainer on your Raspberry Pi, please comment below. You are also very welcome to comment with your experiences and advice in case you have something to add to this article.
Author
Michael Andersen
Michael Andersen is the author of Sustainable Web Design In 20 Lessons and the founder of Sustainable WWW (World-wide-web), an organization teaching sustainable practices. With a passion for web design and the environment, Michael solves puzzles to make the internet more sustainable.

Michael Andersen
Michael Andersen is the author of Sustainable Web Design In 20 Lessons and the founder of Sustainable WWW (World-wide-web), an organization teaching sustainable practices. With a passion for web design and the environment, Michael solves puzzles to make the internet more sustainable.