How to Install Portainer on Ubuntu 20.04 using Docker

Portainer is a versatile tool that focuses on open source container management for Kubernetes, Docker, Docker Swarm, and also Azure ACI. Thanks to this tool, you can easily deploy and manage containers without writing any code. The official website describes it as a tool that you can use to configure and manage environments, deploy applications, monitor application performance, and sort issues.
In order to install Portainer on Ubuntu 20.04, it is recommended to create a container first.

Container creation

Create a directory for portainer to store data. Then you need to create a portainer container. This can be done with the following commands:

mkdir -p /vol/portainer/data
docker run --restart always -d --name=portainer -v /var/run/docker.sock:/var/run/docker.sock -v /vol/portainer/data:/data -e VIRTUAL_HOST=port.example.com -e VIRTUAL_PORT=9000 portainer/portainer-ce -H unix:///var/run/docker.sock

After successfully creating the container, you need to configure a reverse proxy.

Configuring a Reverse Proxy for Portainer

Caddy is a lightweight ZeroSSL reverse proxy server. Caddy simplifies your infrastructure. It takes care of renewing TLS certificates, OCSP stapling, serving static files, reverse proxying, Kubernetes login and more. This means you don’t have to go through a complex HTTPS configuration, it receives and automatically maintains SSL certificates. In this tutorial, Caddy serves a very important function – it is used as a Portainer reverse proxy. To create a CaddyFile, you need to run the following command:

mkdir -p /vol/caddy/configs
nano /vol/caddy/configs/Caddyfile

Then you need to supplement with the text that is indicated below:

port.example.com {
    tls youremail@example.com
    reverse_proxy portainer:8000

Note

port.example.com {is your domain, which has the correct DNS record for your VPS

tls youremail@example.comapplying free security certificates and using this email to get Let’s Encrypt reminders

Creating a Caddy Container

After successlully creating the CaddyFile, create a container using the following command:

docker run --restart always -d -p 80:80 -p 443:443 -v "/vol/caddy/data:/data/caddy" -v "/vol/caddy/configs:/etc/caddy" --link portainer --name caddy caddy

Note

-v “/ vol / caddy / data: / data / caddy” it’s a mount the caddy working directory on your host to save data such as certificates


–link portainer to link the caddy container, the portainer so they can access each other

Installation of Portainer

Visit your domain in a web browser and set your appropriate password. After that, it is assumed that the installation is complete

Was this article helpful?

Related Articles

Leave A Comment?