Portainer — Manage Docker platform with GUI dashboard

Navratan Lal Gupta
Linux Shots
Published in
6 min readOct 9, 2021

Portainer is a Web User Interface (WUI/GUI) dashboard tool, which can be used to monitor and centrally manage a docker platform. With Portainer, We can add/login to a registry, Manage multiple hosts, Manage hosts on different networks, Build a Container (Docker) Image, pull and push an image from/to container registry, Manage running/deployed containers, deploy a stack/container, Manage accounts, and many more.

Other than standalone docker platform, Portainer also supports Docker Swarm and Kubernetes cluster. Above that, All of them can be managed from single centrally managed dashboard UI.

Portainer dashboard

Portainer comes in two editions, Community Edition (CE) and Business Edition (BE). CE is free and open source and BE is to enable Container-as-a-Service at enterprise level with more advanced and enterprise features.

In this article, We will go through installation of Portainer CE on standalone docker platform and how to use the portal to add/login to registry, build an image, deploy a container and few basic usage.

Contents

  1. Prerequisite for installation
  2. Installation
  3. Add new docker host/environment to dashboard
  4. Monitor hosts
  5. Login/Add a container registry
  6. Build a container image and push to registry
  7. Pull an image from registry
  8. Deploy a stack or Container
  9. Run commands inside container (Exec inside container)
  10. Monitor resource usage by a container
  11. Manage accounts

Prerequisites for installation

This demo has been performed on/with:

  • Ubuntu 20.04 Linux server with root access
  • Docker 20.10.8
  • Portainer CE 2.9.0 Alpine
  • Another docker platform in same network (Linux Mint 20.2) (OPTIONAL)

Installation

Portainer has two elements, Portainer server and Portainer agent. Both are lightweight and runs as docker container. Portainer server runs on one host and is the only mandatory element which is required to be deployed. Portainer agent can be deployed on extra hosts (Docker/Kubernetes/Docker swarm) which we need to manage from Portainer dashboard.

  1. Installation requires root access for proper functioning of dashboard.

sudo su

2. Create a docker volume

docker volume create portainer_data

3. Deploy Portainer Server

docker run --detach \
--name portainer \
--publish 9443:9443 \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume portainer_data:/data \
--restart=always \
portainer/portainer-ce:2.9.0-alpine

Port 9443 is used for web UI access. Docker socket is required to be mounted on Portainer container to allow it to access docker daemon.

Portainer creates its own self-signed SSL certificate for secure communication between Portainer Server and User’s browser and between Portainer Server and other Portainer agents.

If you want to add your own certificates, that can be done from web UI, OR

It can also be added during installation using sslcert and sslkey arguments passed.

docker run --detach \
--name portainer \
--publish 9443:9443 \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume portainer_data:/data \
--restart=always \
portainer/portainer-ce:2.9.0-alpine \
--sslcert /path/to/certs/cername.crt --sslkey /path/to/certs/keyname.key

4. Check if portainer container is up and running.

docker ps

5. Open the UI using your browser at https://localhost:9443 or your FQDN (Domain) and setup the admin credential.

First time admin credential setup

Add new docker host/environment

6. Install Portainer Agent on new host and add the new host/environment to dashboard (Optional for adding extra hosts)

docker run --detach \
--port 9001:9001 \
--name portainer_agent \
--restart=always \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /var/lib/docker/volumes:/var/lib/docker/volumes \
portainer/agent:2.9.0-alpine

Portainer Agent listens to Portainer server on port 9001.

Add new environment (host)

Monitor hosts

  1. In Portainer UI, Click on ‘Home’ to display all the connected hosts.
Environments connected to Portainer server

2. Select one of them.

Login/Add a container registry

  1. Settings → Registries → Add registry

2. Choose registry provider, Add username and password.

Build a container/docker image

  1. Images → Build a new image

In images section, We can list all the pulled image in environment.

2. You can write Dockerfile in web editor or upload tarball from local or an URL to build an image.

Output after build

3. After image is built, It will be listed in Images section (Refresh if not listed). Click on the image from list and It can be pushed to registry from there.

Pull an image from registry

  1. Click on images from left panel.
  2. Choose a registry from drop down list. Add image name with tag. And pull the image.

Deploy a stack or a container

Portainer provides some application templates which can be used to deploy an application.

Users can also create their own custom template using docker-compose file. We will use one of template provided by Portainer to deploy an application.

  1. Left panel → App Templates → Select a template from list

2. Fill the fields. We can configure custom ports and others from advanced options.

3. Once deployed. Container will be up and running.

Containers can also be deployed from Left panel → Containers.

Run commands inside container (Exec inside container)

  1. List the images from Left Panel → Containers → Select a running container
  2. Click on ‘console’

3. Give custom command or use shell binary present in container.

Monitor resource usage of a container

  1. Open container from containers list.

2. Click on stats.

Manage Account

  1. Custom authentication methods can be setup under Settings → Settings → Authentication.
Authentication Settings

2. Roles, Teams and Users can be created and managed from Settings → Users sections. This can be used to grant access to other developers and segregate their duties.

Other docker components like Stacks, Containers, Images, Networks, Volumes, Events and hosts can be managed from their respective sections in left panel.

For more detailed information, Must visit Portainer official website here.

Stay tuned for more. Don’t forget to follow and clap if you like this. :)

Thanks

Navratan Lal Gupta

Linux Shots

--

--

Navratan Lal Gupta
Linux Shots

I talk about Linux, DevOps, Kubernetes, Docker, opensource and Cloud technology. Don't forget to follow me and my publication linuxshots.