If you have multiple Docker hosts, sooner or later the question arises: how to manage them from one location without turning it into a zoo of SSH sessions and manual commands. Portainer solves exactly this problem — it provides a single web interface for managing the entire container infrastructure.

Ubuntu 24.04 LTS is selected as the operating system. All the examples of commands and configurations are designed specifically for it. Installation will require access to the server with root rights and a domain with a configured DNS A record.

The following values are used in the examples below: the server’s IP address is 10.10.10.10, and the domain name is portainer.example.com. In your configuration, replace them with your own.

What is a Portainer and how it works

Portainer is a web—based platform for managing container infrastructure through a single GUI and REST API. It connects to Docker, Docker Swarm, and Kubernetes-based environments and allows them to be administered from a single interface. At the same time, Portainer is not an orchestrator — it does not manage the cluster or distribute the load, but works on top of these platforms as a management tool.

Portainer is used for centralized management of containers, images, networks, and volumes via a web interface. You can also use it to deploy applications and configure user access. Advanced features such as flexible authentication and RBAC are available in the paid version.

How the Portainer works

Portainer consists of a central management server (Portainer Server) and pluggable environments. Individual Docker hosts can act as environments, as well as clusters based on Docker, Docker Swarm, and Kubernetes.

The Portainer Server is the main component of the system. It provides a web interface, API, stores settings, and manages connected environments.

There are several ways to connect environments to the Portainer Server.:

  • Docker API / Socket or via Agent — direct connection for local or network-accessible Docker hosts.
  • Edge Agent Standard — for remote sites and nodes behind a NAT, firewall, or unstable connection.

The choice of method depends on network availability, security requirements, and infrastructure features.

The main difference between Agent and Edge Agent Standard is the Portainer server connection model.:

  • The agent server initiates the connection with the agent itself. Suitable for nodes with direct network access.
  • Edge Agent Standard — the agent initiates the connection to the server itself using the periodic polling model. Therefore, it is better suited for remote and isolated environments.

Installing Docker

To install Docker, we will use the official repository, as it allows you to install current versions of packages, rather than older builds from standard Ubuntu repositories.

First, we will update the package index and install the utilities that will be needed to connect the external repository: ca-certificates — to verify TLS certificates, curl — to download the signing key.

apt update
apt install -y ca-certificates curl

Next, we will create a directory for storing APT repository keys, download the official Docker GPG key and configure the correct access rights for it. This key is needed to verify the authenticity of packages from the Docker repository.

install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

After that, we will add the official Docker repository to the list of APT sources. The configuration automatically uses the codename of the current Ubuntu release so that the repository matches the installed version of the system.

tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

Now we will update the package index again so that APT gets information about packages from the new repository, and install the Docker Engine, CLI, containerd, as well as the Buildx and Docker Compose plugins.

apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Installing the Portainer Server

There are various ways to install the Portainer Server: for example, launch the container manually via docker run, deploy via Docker Compose, or use Kubernetes.

In our case, the Docker Compose option was chosen, as it is easier to maintain: all startup parameters are stored in a single YAML file, it is convenient to change the configuration, and the service itself can be restarted and updated with standard Compose commands.

First, let’s create a separate directory for the Portainer files.

mkdir -p /opt/portainer

Next, create a docker-compose file.yml with a description of the service. It sets the Portainer CE image, restart policy, connection to Docker socket, permanent storage for data, and forwarding of necessary ports.

cat > /opt/portainer/docker-compose.yml << EOL
services:
  portainer:
    container_name: portainer
    image: portainer/portainer-ce:2.39.3
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    ports:
      - "127.0.0.1:9443:9443"
      - "10.10.10.10:8000:8000"

volumes:
  portainer_data:
    name: portainer_data

networks:
  default:
    name: portainer_network

EOL

Configuring Nginx + HTTPS

Portainer provides its own web interface on port 9443, but for convenient access by domain name and with a valid TLS certificate, Nginx is usually placed in front of it as a reverse proxy. To issue a certificate, Let’s Encrypt, a free certificate authority, is selected in this instruction.

Before starting the configuration, make sure that the domain name points to the server’s IP address. This is necessary in order for Let’s Encrypt to verify domain ownership and issue a certificate. In our example, the domain portainer.example.com it should point to 10.10.10.10.

You can check this with the command:

dig +short portainer.example.com

The response should display the IP address of your server.

If the domain has not yet been configured, create an A-record in the DNS control panel of the registrar or DNS provider: specify the desired subdomain as the name, and the server’s external IP address as the value.

You also need to make sure that ports 80/tcp and 443/tcp are open on the server: they are needed for HTTP verification of Let’s Encrypt and HTTPS access to the Portainer web interface.

You can check whether the server is listening to the necessary ports after configuring the services with the command:

ss -tulpn | grep -E ':80|:443'

Let’s start configuring Nginx and issuing a TLS certificate.

Step 1. Install Nginx and Certbot.

Install Nginx, Certbot, and the python3-certbot-nginx module, which allows you to automatically issue and connect certificates for Nginx.

apt update
apt install -y nginx certbot python3-certbot-nginx

Add Nginx to the startup and immediately launch the service.:

systemctl enable --now nginx

Step 2. Get the TLS certificate.

We will issue a certificate for the domain — in our case, portainer.example.com. During execution, Certbot may request an email for notifications and acceptance of the terms of use.

certbot --nginx -d portainer.example.com

If the certificate is issued successfully, Certbot will create the certificate files in the /etc/letsencrypt/live/portainer.example.com/.

Step 3. Create the Nginx configuration.

Let’s create a configuration file in which we will configure Nginx as a reverse proxy for Portainer. In this configuration, HTTP requests to port 80 will be automatically redirected to HTTPS, and Nginx itself will proxy HTTPS traffic to local port 9443, where Portainer is running.

Replace the portainer.example.com before executing the command to your domain name.

cat > /etc/nginx/sites-available/portainer.example.com << 'EOL'
server {
  listen 80;
  server_name portainer.example.com;
  location / {
    return 301 https://$host$request_uri;
  }
}

server {
  listen 443 ssl http2;
  server_name portainer.example.com;

  ssl_certificate     /etc/letsencrypt/live/portainer.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/portainer.example.com/privkey.pem;

  ssl_session_cache shared:SSL:10m;
  ssl_session_timeout 1d;
  client_max_body_size 0;

  location / {
    proxy_pass https://127.0.0.1:9443;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_ssl_verify off;
  }
}

EOL

Step 4. Activate the website and apply the configuration.

After creating the configuration, you need to turn on the site, check the Nginx configuration syntax, and restart the service.

ln -s /etc/nginx/sites-available/portainer.example.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx

Configuring the firewall

After installing Portainer, Docker, and Nginx, you should limit incoming and transit network connections at the firewall level. This is necessary so that the server accepts only the necessary connections: for example, SSH for administration, HTTP/HTTPS for web access, and Docker service traffic. This approach reduces the attack surface — the fewer open ports and allowed connections, the more difficult it is for an attacker to find a vulnerability — and makes the network configuration more predictable.

In Ubuntu, the ufw utility is often used for basic firewall configuration, however, nftables is selected in this instruction. This is a modern built-in traffic filtering mechanism in Linux, which gives more flexibility and is better suited for fine-tuning the rules, especially if the server is running Docker.

In this scheme, we need to allow only the traffic that is actually in use.:

  • 22/tcp — for SSH access to the server;
  • 80/tcp — for HTTP and passing Let’s Encrypt verification;
  • 443/tcp — for HTTPS access to the Portainer web interface via Nginx;
  • 8000/tcp — for Portainer service communication with Edge Agent Standard.

So, let’s start configuring the firewall.

Step 1. Disable UFW and install nftables

If ufw is enabled on the server, it is better to disable it so as not to mix two different firewall management mechanisms. After that, we will install the nftables package.

systemctl disable --now ufw
apt remove -y ufw
apt install -y nftables

Step 2. Create the rules configuration

The following is an example of the configuration of the /etc/nftables.conf file. It is needed in order to explicitly describe which traffic is allowed to the server and which will be blocked.

In this configuration, incoming and transit connections are prohibited by default, but already established connections, local traffic, SSH access, as well as HTTP/HTTPS for Nginx and the Portainer web interface are allowed. The network interaction between Docker and Edge Agent Standard is taken into account separately.

cat > /etc/nftables.conf << 'EOL'
#!/usr/sbin/nft -f

define EDGE_AGENT_STANDARD = { 127.0.0.1 }

table inet filter {
  chain input {
    type filter hook input priority filter + 1; policy drop;
    ct state vmap { established : accept, related : accept, invalid : drop }
    ip protocol icmp limit rate 4/second accept
    ip6 nexthdr ipv6-icmp limit rate 4/second accept
    ip protocol igmp limit rate 4/second accept
    iif lo ct state new accept
    tcp dport ssh ct state new accept
  }
}
# First, we delete the old table so that there are no conflicts/duplicates when reloading the rules.
delete table inet filter

# Basic configuration
table inet filter {
  chain input {
    type filter hook input priority filter + 1; policy drop;

    ct state vmap { established : accept, related : accept, invalid : drop }

    ip protocol icmp limit rate 4/second accept
    ip6 nexthdr ipv6-icmp limit rate 4/second accept
    ip protocol igmp limit rate 4/second accept

    iif lo ct state new counter accept

    # SSH
    tcp dport ssh ct state new counter accept

    # HTTP/HTTPS (UI + API + Edge Agent polling)
    tcp dport { http, https } ct state new counter accept
  }
  chain forward {
    type filter hook forward priority filter; policy drop;

    ct state vmap { established : accept, related : accept, invalid : drop }

    # Docker bridge-сети
    iifname "docker0" ct state new counter accept
    iifname "br-*" ct state new counter accept

    # Edge Agent Standard tunnel
    ip saddr $EDGE_AGENT_STANDARD ip protocol tcp ct original proto-dst 8000 ct state new counter accept
  }
}

EOL

Adding new Edge Agents: If Edge Agent Standard connects from other Docker hosts, their IP addresses must be added to the EDGE_AGENT_STANDARD variable. For example:

define EDGE_AGENT_STANDARD = { 192.168.1.10, 192.168.1.11, 10.0.0.5 }

After changing the file, apply the configuration: nft -f /etc/nftables.conf

Step 3. Enable nftables and apply the rules

Now turn on the nftables service so that the rules are loaded automatically at system startup, then restart Docker and apply the configuration manually.

systemctl enable --now nftables
systemctl restart docker
nft -f /etc/nftables.conf

You need to restart Docker because it adds its own network rules to the system. This is important to consider when working with a firewall.

Verification: After applying the configuration, it is useful to make sure that the rules are actually loaded.:

nft list ruleset

You can also check that the server is listening to the correct ports.:

ss -tulpn | grep -E ':22|:80|:443|:8000'

If everything is configured correctly, the server will accept only the necessary connections, and all other incoming connections will be blocked by nftables rules.

Important: systemctl restart nftables completely re-reads the configuration and deletes the dynamic rules that were added by Docker. Because of this, containers may lose network access. Therefore, it is safer to use this order:

  • Make changes to /etc/nftables.conf and apply only via nft -f /etc/nftables.conf;
  • If you did, immediately restart Docker with the systemctl restart docker command to restore Docker rules.

Launching the Portainer

After preparing the docker-compose.yml let’s launch the Portainer Server. To do this, go to the configuration directory and run the container in the background.:

cd /opt/portainer
docker compose up -d

After executing the Docker Compose command, it downloads the portainer/portainer-ce image, creates the necessary objects, and launches the Portainer container.

Important: after the first launch, you will have 5 minutes to create an administrative user through the web interface. If no account is created during this time, the container will need to be restarted.

Verification: after launching, make sure that the service is working correctly. First, check that the container is running:

docker ps

The output must contain a portainer container with the Up status. Then open the address in the browser. In our case, this is https://portainer .example.com.

If everything is configured correctly, the Portainer startup interface opens with a valid TLS certificate.

If the Edge Agent Standard is used in the infrastructure, the connection to the server is performed on two ports.:

- https://portainer.example.com — the main interface and API is via 443/tcp, which is proxied to 9443;
- portainer.example.com:8000 is the service port for the Edge Agent tunnel.

So, we performed the manual installation and basic configuration of the Portainer Server: we deployed the service, configured Nginx, HTTPS and firewall, and also checked that the web interface is available.

This completes the basic installation, and the Portainer server with HTTPS access is ready to work. Now you can use it as a central control point for the Docker environment.

However, many of the Portainer’s features go beyond the scope of this instruction. It can also be used to connect remote Docker hosts via Edge Agent, deploy applications via Stacks, configure users and access rights, and integrate external authentication via Keycloak.