20

How to Install Portainer on Ubuntu 20.04 with Docker

 2 years ago
source link: https://www.vultr.com/docs/how-to-install-portainer-on-ubuntu-20-04-with-docker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
<?xml encoding="utf-8" ??>

Introduction

Portainer is a powerful container management tool for Kubernetes and Docker. This tutorial explains how to install the Portainer with Docker on Ubuntu 20.04.

Prerequisites

Example Names

This guide uses example names.

  • port.example.com : Example domain with the correct DNS record to your instance.
  • [email protected]: Example email to receive Let's Encrypt reminders. Replace it with a real email address, or Let's Encrypt will not issue a certificate to you

1. Create a Container

Create a directory for the Portainer to store data, then create a Portainer container.

$ sudo 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
  • -v /var/run/docker.sock:/var/run/docker.sock means mounting /var/run/docker.sock to the container so portainer can control the Docker.
  • -v /vol/portainer/data:/data means storing data of portainer on directory /vol/portainer/data.
  • port.example.com is your domain to access the portainer.

2. Configure Reverse Proxy for Portainer

HTTPS is a necessary security measure to protect your data from network hijacking. Caddy is a light ZeroSSL reverse proxy server. It means that you don't need to consider complex HTTPS configuration, it obtains and automatically maintains SSL certificates. This tutorial uses Caddy for reverse proxy Portainer.

Create a Caddyfile

Caddyfile is a document containing configs for your sites. Create a Caddyfile:

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

Then populate it with the following text:

port.example.com {
    tls [email protected]
    reverse_proxy portainer:8000
}
  • port.example.com is your domain with the correct DNS record to your instance.
  • tls [email protected] means apply free certificates and use this email to receive Let's Encrypt reminders.
  • reverse_proxy portainer:8000 means forward request to 8000 port on container portainer.

Press :KEYCTRL: + :KEYX: to save the file.

Create a Caddy Container

After compose the Caddyfile, create a container with 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
  • -p 80:80 -p 443:443 means publish its 80 and 443 port to your host so you can access it with those ports.
  • -v "/vol/caddy/data:/data/caddy" means mount caddy working directory to your host to persist data such as certificates.
  • -v "/vol/caddy/configs:/etc/caddy" means mount caddy configuration directory to your host to persist configurations.
  • --link portainer means link container caddy with portainer so they can access with each other.

3. Install Portainer

Visit your domain in a web browser and set a password to finish the installment.

More Resources

Want to contribute?

You could earn up to $600 by adding new articles


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK