How to Deploy Portainer on a VPS
Updated Nov 2026
verified on Ubuntu 26.04 · Nov 2026Self-host Portainer CE on a VPS behind Caddy HTTPS with Docker Compose, claim the admin with the setup token, and back up and restore it.
- A VPS (see Server sizing below)
- A fresh Ubuntu 26.04 server with root/sudo SSH access
- A domain or subdomain you can point at the server
What you are building
Portainer CE is a web UI for containers, images, volumes and Compose stacks. Its Community Edition is zlib-licensed, and the project's README describes it as intended for homelabs and other non-production use. If you only manage Compose files, Dockge is a smaller option.
Portainer mounts the Docker socket, which is root access to the server. Anyone who signs in as its administrator owns the machine. Use a long password, and consider limiting who can reach the hostname at all.
Server sizing
On the catalog's test box Portainer measured about 19 MB of memory idle and about 190 MB of disk. The containers you manage with it are what you size for.
Prepare the server
Update the system and install the tools this guide uses:
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install -y curl openssl ufw dnsutils
If you're logged in as root, create a non-root sudo user and continue as that user:
adduser deploy
usermod -aG sudo deploy
Open SSH and the two ports the reverse proxy needs:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
A published Docker port goes around ufw, so the Compose file below decides
what is reachable: Portainer gets no public port of its own.
Paid link — we earn a commission if you shop through it.
Install Docker
If Docker isn't on the server yet, the convenience script installs Docker Engine and the Compose plugin (the Docker and Compose on Ubuntu guide covers the details):
command -v docker >/dev/null || curl -fsSL https://get.docker.com | sudo sh
sudo docker compose version
Configure the stack
Replace docker.example.com with your hostname:
mkdir -p ~/portainer && cd ~/portainer
DOMAIN=docker.example.com
[ -f .env ] || ( umask 077
{ echo "DOMAIN=$DOMAIN"
echo "ADMIN_PASSWORD=$(openssl rand -hex 16)"
echo "BACKUP_PASSWORD=$(openssl rand -hex 16)"
} > .env )
Portainer publishes no ports. Caddy reaches it over the Compose network, so it runs with plain HTTP enabled inside that network only. Port 8000, used by Edge agents, is left out.
cd ~/portainer
cat > docker-compose.yml <<'EOF'
services:
portainer:
image: portainer/portainer-ce:2.45.4
restart: unless-stopped
command: --http-enabled
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
environment:
DOMAIN: ${DOMAIN}
volumes: ["./Caddyfile:/etc/caddy/Caddyfile:ro", "caddy_data:/data"]
depends_on: [portainer]
volumes:
portainer_data:
caddy_data:
EOF
cat > Caddyfile <<'EOF'
{$DOMAIN} {
reverse_proxy portainer:9000
}
EOF
sudo docker compose up -d
HTTPS and the domain
Create an A record for your hostname pointing at the server's public IP and confirm it resolves before Caddy asks for a certificate:
dig +short docker.example.com
Caddy requests the certificate once the name resolves and renews it on its own (see Automatic HTTPS with Caddy). Wait for Portainer to answer through it:
. ~/portainer/.env
code=000
for i in $(seq 1 30); do
code=$(curl -s -o /dev/null -w '%{http_code}' "https://$DOMAIN/api/system/status")
[ "$code" = 200 ] && break
sleep 5
done
echo "Portainer over HTTPS answered $code"; [ "$code" = 200 ]
Create the administrator
A new Portainer prints a setup token to its log and requires it to create the first account. It also only waits 5 minutes after starting; if you are late, restart the container. So restart now and read the token:
cd ~/portainer
sudo docker compose restart portainer
sleep 10
TOKEN=$(sudo docker compose logs --no-log-prefix portainer | grep -o 'setup_token=[0-9a-f]*' | tail -n 1 | cut -d= -f2)
[ -n "$TOKEN" ] && echo "setup token found"
In the browser, open https://docker.example.com, paste the token and choose a
password. Or create the account from the server with the password in .env:
cd ~/portainer
. ./.env
curl -sf -o /dev/null -w 'admin init: %{http_code}\n' -X POST "https://$DOMAIN/api/users/admin/init" \
-H "X-Setup-Token: $TOKEN" -H 'Content-Type: application/json' --data @- <<EOF
{"Username":"admin","Password":"$ADMIN_PASSWORD"}
EOF
Sign in and add the local Docker environment (the browser wizard offers it; this does the same over the API):
cd ~/portainer
. ./.env
cat > login.sh <<'EOF'
. ~/portainer/.env
curl -sf -X POST "https://$DOMAIN/api/auth" -H "Origin: https://$DOMAIN" --data @- <<IN | cut -d'"' -f4
{"username":"admin","password":"$ADMIN_PASSWORD"}
IN
EOF
JWT=$(sh login.sh)
curl -sf -o /dev/null -w 'add environment: %{http_code}\n' -X POST "https://$DOMAIN/api/endpoints" \
-H "Authorization: Bearer $JWT" -H "Origin: https://$DOMAIN" -F Name=local -F EndpointCreationType=1
Keep the admin password in your password manager.
Backups
Portainer has a built-in backup (Settings in the UI) that downloads its own data, optionally encrypted with a password. The same call works from the shell:
cd ~/portainer
. ./.env
JWT=$(sh login.sh)
( umask 077
curl -sf -X POST "https://$DOMAIN/api/backup" -H "Authorization: Bearer $JWT" -H "Origin: https://$DOMAIN" \
-H 'Content-Type: application/json' -o ~/portainer-backup.tar.gz.encrypted --data @- <<EOF
{"password":"$BACKUP_PASSWORD"}
EOF
tar czf ~/portainer-config.tar.gz .env docker-compose.yml Caddyfile login.sh )
test -s ~/portainer-backup.tar.gz.encrypted && ls -lh ~/portainer-backup.tar.gz.encrypted ~/portainer-config.tar.gz
Copy both off the server. This backs up Portainer's settings, users and stack definitions, not the volumes or data of your other containers. Back those up separately.
Restore
Restore is only accepted by a fresh, uninitialised Portainer. This deletes the
current Portainer volume. On a new server, unpack portainer-config.tar.gz
into ~/portainer first.
The backup file is encrypted, so only Portainer can prove that it opens. The block
therefore checks that the file is there and readable, saves a copy of the current
volume as ~/portainer-before-restore-*.tar.gz, and stops at the first error:
(
set -e
cd ~/portainer
. ./.env
test -s ~/portainer-backup.tar.gz.encrypted
head -c 1 ~/portainer-backup.tar.gz.encrypted >/dev/null
sudo docker compose stop portainer
if sudo docker volume inspect portainer_portainer_data >/dev/null 2>&1; then
( umask 077
sudo docker run --rm -v portainer_portainer_data:/d:ro caddy:2 tar czf - -C /d . > ~/portainer-before-restore-$(date +%s).tar.gz )
fi
sudo docker compose rm -sf portainer
sudo docker volume rm -f portainer_portainer_data
sudo docker compose up -d
sleep 10
TOKEN=$(sudo docker compose logs --no-log-prefix portainer | grep -o 'setup_token=[0-9a-f]*' | tail -n 1 | cut -d= -f2)
[ -n "$TOKEN" ]
curl -sf -o /dev/null -w 'restore: %{http_code}\n' -X POST "https://$DOMAIN/api/restore" \
-H "X-Setup-Token: $TOKEN" -H "Origin: https://$DOMAIN" \
-F password="$BACKUP_PASSWORD" -F file=@"$HOME/portainer-backup.tar.gz.encrypted"
)
Portainer restarts itself with the restored data. Sign in with the old password and check the environment is back:
cd ~/portainer
. ./.env
JWT=
for i in $(seq 1 30); do JWT=$(sh login.sh) && [ -n "$JWT" ] && break; sleep 3; done
curl -sf "https://$DOMAIN/api/endpoints" -H "Authorization: Bearer $JWT" | tee /tmp/e.json; echo
grep -q '"Name":"local"' /tmp/e.json
The browser restore screen offers the same upload during first-time setup.
Upgrades
Read the release notes and
take a backup. This guide pins 2.45.4, an LTS release; change the tag and
recreate:
cd ~/portainer
sudo docker compose pull
sudo docker compose up -d
sudo docker compose ps
Troubleshooting
cd ~/portainer && sudo docker compose logs --tail=100 portainer caddy
If setup says the instance timed out, sudo docker compose restart portainer
and use the new token.
Next steps
Compare providers in Best VPS for self-hosting.
Next steps
Common questions
How long does it take to follow "How to Deploy Portainer on a VPS"?
We estimate about 20 minutes of hands-on time for "How to Deploy Portainer on a VPS"; this is an editorial estimate, not a measurement.
Was the "How to Deploy Portainer on a VPS" guide tested?
The "How to Deploy Portainer on a VPS" guide was verified end-to-end on Ubuntu 26.04 (Nov 2026).