Skip to main content

How to install Portainer with Docker

Portainer is a free and open-source lightweight service delivery platform for containerized applications that can be used to manage Docker, Kubernetes, Docker swarm, etc. The application is simple to deploy and use. The application allows you to manage all your container services via smart GUIs or an extensive API, this makes the developers’ work easier.

Portainer gives developers a chance to deploy, manage, and troubleshoot containerized applications without needing to deeply have experience with Kubernetes. This is awesome in my view.

In this tutorial we are going to learn how to install Portainer inside a docker container, also we will learn the uses of Portainer, what are Portainer agents. Also, we need to understand about Portainer ports i.e which ports do Portainer uses to communicate with the world. So let’s dive in

We have two editions of Portainer, the Portainer community edition which is free to use, and the Portainer Business Edition which requires one to purchase the license fee to use and it has more features compared to the community edition.

# Why you need Portainer?

The reason why we need to use Portainer in our case is because of the following reasons:

  • Portainers streamline the operations of container management so that enterprise can focus on other pressing needs.
  • Portainer removes the complexity associated with deploying and managing containers
  • Portainer is the best tool to offer security to every enterprise giving good governance to any institution.
  • Portainer works well with Docker, Kubernetes, Docker swarm, meaning you have tone of applications to deploy with incase you are not well familiar with one, you can switched to another.
  • Portainer can manage networks for you within the GUI, os your work is to add, remove, or edit network endpoints configurations with ease.
  • Portainers easily manages containers for you easily.

# What are Portainer Agents?

Portainer has two elements, the Portainer server, and the Portainer agent. Think of a Portainer agent as the helper, it gets the information on behalf of the server, then goes ahead to negotiate how that info will be conveyed to the intended recipient. This is also how a Portainer agent works, Portainer agents are deployed to each node in your cluster and configured to report back to the Portainer server container.

A single Portainer server can accept connections from many Portainer agents.

## Portainer edge agent

Think of a situation where you are working outside of your organization network, here the Portainer agents cant communicate with the Portainer server as intended because you are on a separate network. In this situation Poratiner edge agents come in, the remote environment only needs to access the Portainer server rather than the Portainer server needing access to the remote environment. This communication is managed by the Portainer edge agent.

## Portainer ports

Every application which needs to communicate with the outside world requires some ports to be open so that it allows full access to the website resources. This is the same case with the Portainer, it requires certain ports for communication.

Portainer Server listens on port 9443 for UI and API and exposes a TCP tunnel server on port 8000.

Portainer agents listen on port 9001.

# Prerequisites

  • You need to have Docker version 20 + for you to run Portainer 2 and above.
  • Have basic knowlege of commanline
  • 20 + GB diskspace
  • Have sudo access

# Install Portainer CE with Docker

We are going to install the Portainer community edition because it’s free. I am also going to run docker on Ubuntu 20.04

## Run system updates

To start off, we need to run system update in order to make our repositories up to date.

$ sudo apt update && apt upgrade
# you can reboot your system afterwards

# Install Docker on Ubuntu 20.04

We need to first have Docker up and running before we can install Portainer. Check out this article on how to install Docker on Ubuntu 20.04. Definitely, you can use other distributions as you like.

So to install follow these steps

Remove installed docker if you had installed another version

$ sudo apt remove docker 

Then install Docker

$ sudo apt install docker.io -y

You can check the version of installed Docker with:

$ docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2

We have successfully installed Docker version 20.10.7 suitable for Portainer installation

You need to enable and start docker

# enable docker 
$ sudo systemctl enable docker 
# start docker 
$ sudo systemctl start docker 
# check status 
$ sudo systemctl status docker 
# docker start output
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-01-15 11:13:48 UTC; 3min 4s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 17244 (dockerd)
      Tasks: 8
     Memory: 50.9M
     CGroup: /system.slice/docker.service
             └─17244 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jan 15 11:13:48 ubuntu dockerd[17244]: time="2022-01-15T11:13:48.719137739Z" level=warning msg="Your kernel does>

# Install Portainer with Docker

Let’s dive into the installation of Portainer with Docker. Begin by creating a Portainer volume that will store Portainer server data

$ docker volume create nextgen_data

You will get nextgen_data as output

The next thing is to download and install the Portainer server

$ docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v nextgen_data:/data \
    portainer/portainer-ce

This will be the sample output

Unable to find image 'portainer/portainer-ce:latest' locally
latest: Pulling from portainer/portainer-ce
0ea73420e2bb: Pull complete 
c367f59be2e1: Pull complete 
b71b88d796e2: Pull complete 
Digest: sha256:4f126c5114b63e9d1bceb4b368944d14323329a9a0d4e7bb7eb53c9b7435d498
Status: Downloaded newer image for portainer/portainer-ce:latest
abc0e25a561112a640a829f64cc15bd593847a619fab9553f33b0754a876e965

-d means running a container in a detached mode

-p shows the port number to use

-v represents the volume

To check if Portainer has been installed successfully run the docker ps command

$ docker ps

If you get the following output then you are good to continue

CONTAINER ID   IMAGE                    COMMAND        CREATED              STATUS              PORTS                                                                                            NAMES
abc0e25a5611   portainer/portainer-ce   "/portainer"   About a minute ago   Up About a minute   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp, 9000/tcp   portainer

Now that we have installed Portainer, the next thing is to access its GUI interface via the web browser.

https://<your_IP_address>:9443

You will be greeted with the following interface.

Portainer Login page

Portainer Login page

Choose a strong password and login

Portainer Dashboard

Portainer Dashboard

Use Docker as the local environment. You will get the following screen

Portainer interface

Portainer interface

You can continue experimenting with different properties Portainer has.

# Conclusion

Congratulations, you have successfully installed Portainer with docker. If you got any issue, always consult the Portainer documentation.