Portainer CE is a free and open-source tool that manages all your docker containers. It has a nice clean web UI where you can inspect and control all your docker resources. With this tutorial, you can install Portainer easily on Ubuntu with a simple docker run command, use a docker-compose file, or even deploy it in a Kubernetes environment. In this tutorial, let’s have a look at how to install Portainer on an Ubuntu server.
Install Portainer on Ubuntu tutorial
First, you need to install Docker on Ubuntu. I’ve made a video about it, or you can just follow the official docker documentation. If you want to install Portainer with docker in a cloud environment, I can recommend DigitalOcean. They have a pre-build Droplet image with Ubuntu and Docker already installed.
First, let’s create a new volume to store the data persistently.
docker volume create portainer_data
Then we can simply launch the Docker container.
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
(Optional) Reverse Proxy with NGINX Proxy Manager
I recently made a tutorial about deploying the NGINX Proxy Manager as a reverse proxy, watch it first! You can use this to obtain trusted SSL certificates and expose Portainer securely. Note, that when you want to use NGINX Proxy Manager with Portainer, you need to put both containers in the same network, and don’t expose the admin port 9000. Here is a slightly modified version of the docker command to run Portainer with the NGINX proxy manager.
docker run -d -p 8000:8000 --network nginxproxymanager_default --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
After deploying the portainer container, you can open NGINX Proxy Manager and create a new proxy host that will expose port 9000 of Portainer securely with letsencrypt certificates.
Login to the Portainer web UI
When you first log in to the Portainer web UI on port 9000, you need to create a password. After setting up this you need to select your environment. You can choose to manage the local Docker environment (this is what we want to do). But you can also manage any local Kubernetes environment or connect to the Portainer Agent, to manage remote servers.
Select the local Docker environment and connect.
Now, you should see the Home Dashboard. If you connected remote servers through “Endpoints”, you see all your servers here. We only have connected Portainer to the local Docker environment. If you’re running Portainer with NGINX Proxy Manager you will notice that we’re already running 3 containers. That is because Portainer can manage all existing Docker resources, even if you haven’t deployed them via Portainer, but terminal commands or compose files.
How to deploy containers with Portainer
With Portainer, you can easily create new docker resources. But the best feature compared to Docker terminal commands is, that you can also edit or change your existing resources. You can also monitor your running containers, start and stop them, and so on.
App Templates can help you to quickly deploy applications with pre-defined volumes, environment settings, and so on. For example, you can simply deploy databases, webservers, or well-known applications.
Before creating a container you need to add all networks or volumes, you want to use, first. This is pretty easy and straight-forward if you’re familiar with the concepts of Docker and containers.
Volumes in Portainer
Networks in Portainer
Containers in Portainer
Deploy docker-compose stacks with Portainer
You can also deploy docker-compose files with Portainer in so-called “stacks”. You can use the web editor to simply copy and paste a compose file. Upload it from your computer. Use a Git Repository, or use a custom template.
You can also browse existing templates or define custom ones if you want to define some recipes for containers that you usually deploy often.
You can also manage existing stacks, you have deployed with docker-compose manually on the system. For example, if you followed my NGINX Proxy Manager tutorial with docker-compose, you should see the stack. However, because Portainer is not fully managing the compose file, the access is limited.