This tutorial installs Portainer CE 2.45.4 LTS on an Ubuntu 24.04 VPS with Docker Compose and puts the dashboard behind Caddy 2.11.9 with automatic HTTPS. Only ports 80 and 443 are open: Portainer's 9443, 9000 and 8000 are never published. It also covers the setup token introduced in 2.45, the 5-minute window to create the administrator, the first stack, backup with a restore, and the upgrade. Everything was tested on 30 November 2026 on a clean Ubuntu 24.04.5 LTS machine.
On this page
- What Portainer does and what it can reach
- Versions used
- What you need
- 1. Install Docker from the official repository
- 2. Open only what is needed in the firewall
- 3. Create the files
- 4. Validate and start
- 5. Create the administrator with the setup token
- 6. Connect the local environment and deploy the first stack
- 7. Check what is exposed
- Backup and restore
- Upgrade Portainer
- Common problems
- What was not tested
- Next steps

What Portainer does and what it can reach
Portainer is a web dashboard for Docker. It shows containers, images, volumes and networks, reads logs, opens a console and deploys stacks, which are Compose files managed from the dashboard.
To do that it gets the Docker socket (/var/run/docker.sock). Whoever controls the socket controls the server: they can start a privileged container and read any file on the host. The Docker documentation says only trusted users should be allowed to control the daemon. In practice, the Portainer administrator password is worth as much as the root password. That is why this guide does not publish the dashboard ports, uses HTTPS from the first login and is careful about how the administrator is created.
Versions used
| Component | Version | Source |
|---|---|---|
| Portainer CE | 2.45.4 LTS (18 Nov 2026) | Portainer releases |
| Caddy | 2.11.9 | Caddy releases |
| Docker Engine | 29.10.1 | official apt repository |
| Docker Compose | v5.8.1 (plugin) | official apt repository |
| System | Ubuntu 24.04.5 LTS, amd64 |
The image tags are pinned in the files. Do not use latest: the dashboard that controls the server should not change version on its own.
What you need
- A VPS running Ubuntu 24.04 and a user with
sudo. The examples use a user nameddeploy. - A subdomain with a DNS
Arecord pointing to the VPS IP. The examples useportainer.example.com. - Ports 80 and 443 free on the VPS, so Caddy can issue the certificate.
At rest, Portainer used about 90 MiB of RAM and Caddy 64 MiB. The dashboard fits on any plan; what sizes the VPS is the applications you will run on it.
1. Install Docker from the official repository
These are the commands from the Docker documentation for Ubuntu, which now writes the repository in the docker.sources format:
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginAdd your user to the docker group to run commands without sudo, then log out of the SSH session and back in:
sudo usermod -aG docker $USERAfter logging back in, check:
docker version --format '{{.Server.Version}}'
docker compose version
docker run --rm hello-world2. Open only what is needed in the firewall
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw enable
sudo ufw status verboseufw enable warns that it may disrupt SSH connections; answer y, since port 22 is already allowed. 443/udp is for Caddy's HTTP/3.
3. Create the files
Create the folder and a .env with your domain:
mkdir -p ~/portainer && cd ~/portainerPORTAINER_DOMAIN=portainer.example.comThe Caddyfile has a single block. Caddy requests the certificate, redirects HTTP to HTTPS and forwards everything, including the console WebSockets, to Portainer:
{$PORTAINER_DOMAIN} {
reverse_proxy portainer:9000
}In docker-compose.yml, only Caddy has ports:. Portainer stays on the internal network and takes no flags:
name: portainer
services:
portainer:
image: portainer/portainer-ce:2.45.4
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
networks:
- proxy
caddy:
image: caddy:2.11.9
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
PORTAINER_DOMAIN: ${PORTAINER_DOMAIN:?set PORTAINER_DOMAIN in .env}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- proxy
depends_on:
- portainer
networks:
proxy:
volumes:
portainer_data:
caddy_data:
caddy_config:Two details of this layout came out of the test:
- The proxy targets port 9000, over HTTP, inside the Docker network. With
reverse_proxy https://portainer:9443, Caddy changes theHostheader and Portainer rejects the login with403 Forbidden, because its CSRF protection comparesOriginwithHost. With 9000, Caddy keeps theHostand--trusted-originsis not needed. - Port 8000 is left out. It serves the Edge agent tunnel, which this guide does not use.
4. Validate and start
Validate both files before starting:
cd ~/portainer
docker compose config -q && echo CONFIG_OK
docker run --rm --env-file .env -v "$PWD/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2.11.9 caddy validate --config /etc/caddy/CaddyfileThe second command ends with Valid configuration. Start the stack and check it:
docker compose up -d
docker compose ps
curl -fsS https://portainer.example.com/api/system/status{"Version":"2.45.4","InstanceID":"c6f29658-6f45-451f-a445-ef9cf40f2732"}In docker compose ps, only Caddy shows 0.0.0.0:80->80/tcp and 0.0.0.0:443->443/tcp. Portainer is listed with 8000/tcp, 9000/tcp, 9443/tcp and no arrow: those are container ports, not host ports.
5. Create the administrator with the setup token
Version 2.45 prints a token in the log on first start. Without it, nobody can create the administrator or restore a backup, even if they reach the screen before you do. Get the token:
docker compose logs portainer | grep setup_tokensetup_token=<64 hexadecimal characters>Open https://portainer.example.com. On the New Portainer installation screen, fill in Username (prefilled with admin), Password and Confirm password with a password of at least 12 characters, paste the token into Setup token and click Create user.
Keep the password in a password manager and do not reuse it.
6. Connect the local environment and deploy the first stack
After Create user comes the Set up Edge Compute screen; click Skip. Next, the Environment Wizard shows "We have connected your local environment of Docker to Portainer". Click Get Started: the local environment is the Docker of the VPS itself.
To deploy a stack:
- On Home, click the
localenvironment. - In the side menu, open Stacks and click Add stack.
- Name it
whoamiand keep the Web editor build method. - Paste the Compose below and click Deploy the stack.
services:
whoami:
image: traefik/whoami:v1.11.0
restart: unless-stoppedThe stack takes a few seconds to go from deploying to active. Check from the terminal:
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'NAMES IMAGE STATUS
whoami-whoami-1 traefik/whoami:v1.11.0 Up 8 seconds
portainer-caddy-1 caddy:2.11.9 Up 6 minutes
portainer-portainer-1 portainer/portainer-ce:2.45.4 Up 6 minutesThe stack list also shows portainer, with Limited control. That is the Compose from this guide: Portainer can see it but not edit it, because it was created from the terminal. Keep changing that stack through the files in ~/portainer.
To open a terminal inside a container, go to Containers, click the container and then Console. The Command field defaults to /bin/bash. On Alpine images, such as Caddy's, switch it to /bin/sh before clicking Connect, or the connection opens and drops right away.
7. Check what is exposed
On the VPS, list what is listening:
sudo ss -tulpn | grep -E ':(22|80|443|8000|9000|9443)\b'Only SSH on 22 and docker-proxy on 80 and 443 should appear. From your own computer, test the Portainer ports against the VPS IP:
curl -m 5 -k https://VPS-IP:9443
curl -m 5 http://VPS-IP:9000Both commands must time out. In the test, 9443, 9000 and 8000 did not answer from outside, and port 80 returned 308 to HTTPS.
Backup and restore
The Portainer backup holds the configuration: users, environments, the Compose of each stack and the keys. It does not hold containers, images or the volumes of your applications. The screen itself says so: "This will back up your Portainer server configuration and does not include containers".
In Settings > General > Back up Portainer, turn on Password Protect, enter a password and click Download backup. The file is named portainer-backup_YYYY-MM-DD_HH-MM-SS.tar.gz.encrypted, encrypted with AES-256-GCM and stamped in UTC. Keep the file and the password off the VPS.
To automate it, the API does the same. This block asks for the administrator password and writes the backup to the current folder. The password goes straight into the JSON: if it contains double quotes or a backslash, type those characters preceded by \:
read -rsp "Admin password: " PW; echo
JWT=$(curl -fsS https://portainer.example.com/api/auth -H 'Content-Type: application/json' \
-d "{\"Username\":\"admin\",\"Password\":\"$PW\"}" | sed -E 's/.*"jwt":"([^"]+)".*/\1/')
curl -fsS -X POST https://portainer.example.com/api/backup -H "Authorization: Bearer $JWT" \
-H 'Content-Type: application/json' -d '{"password":"BACKUP-PASSWORD"}' \
-o "portainer-backup-$(date +%F).tar.gz.encrypted"A restore only works on a new instance with no administrator. In the test, the volume was deleted, Portainer started clean and the backup came back like this:
TOKEN=$(docker compose logs portainer | grep -o 'setup_token=[0-9a-f]*' | tail -1 | cut -d= -f2)
curl -fsS -X POST https://portainer.example.com/api/restore -H "X-Setup-Token: $TOKEN" \
-F "[email protected]" -F "password=BACKUP-PASSWORD"The first screen offers the same thing under Restore Portainer from backup, which also asks for the setup token. After the restore, the user, the password, the local environment and the whoami stack with its Compose were back. The stack's container did not come back on its own. To start it again, open the stack, go to the Editor tab, click Update the stack and confirm with Update. With the wrong password, the API answers Failed to decrypt the archive and the instance is left untouched.
Application data needs its own backup. Automatic VPS backups with restic covers volumes and databases.
Upgrade Portainer
Read the release notes, take a backup and change the tag in docker-compose.yml. The example goes from 2.45.3 to 2.45.4; use the version you have and the one you are installing:
cd ~/portainer
sed -i 's|portainer/portainer-ce:2.45.3|portainer/portainer-ce:2.45.4|' docker-compose.yml
docker compose config -q
docker compose pull
docker compose up -d
curl -fsS https://portainer.example.com/api/system/statusIn the test, from 2.45.3 to 2.45.4, only the Portainer container was recreated. The log showed migrating database from version 2.45.3 to 2.45.4, and the user, the environment and the stack were still there. The whoami stack did not even restart. Before migrating, Portainer keeps a copy of the database at /data/backups/portainer.db.bak, inside the volume.
Common problems
- "Your Portainer instance timed out for security purposes": the 5 minutes passed with no administrator. Run
docker compose restart portainerand use the new token. Invalid or missing setup token(403): the token you pasted is not the current one. It changes on every restart; get it from the log again.Password does not meet the requirements(400): the password has fewer than 12 characters.Forbiddenon login, withCSRF check failed ... Origin does not match Hostin the log: the proxy is changing theHostheader or points tohttps://portainer:9443. Usereverse_proxy portainer:9000as in this guide. If you need a different setup, the--trusted-origins https://portainer.example.comflag allows the domain.unrecognized global option: reverse_proxyincaddy validate: thePORTAINER_DOMAINvariable did not reach Caddy. Check the.envand the--env-filein the command.required variable PORTAINER_DOMAIN is missing a value: the.envdoes not exist or is in another folder.- The console connects and drops: the image has no
/bin/bash. Choose/bin/sh.
What was not tested
The test ran on a virtual machine with no public IP. Real DNS, the public Let's Encrypt certificate and HTTP/3 were left out; in place of the domain, Caddy used its internal certificate authority with the same Caddyfile. Restoring through the browser screen, restoring a backup taken on a different version and an upgrade larger than a patch were not tested either. The memory figures come from that virtual machine and are an order of magnitude.
Next steps
- For a dashboard that also builds and deploys from Git, compare with How to install Coolify on a VPS securely and Coolify vs Dokploy.
- To run n8n as a stack, start from the Compose in How to install n8n with Docker on a VPS.
- To pick a server, see the Docker VPS and Linux VPS plans with Ubuntu 24.04.