Docker + Portainer on a VPS: install, web panel and safe access
Docker runs every application in its own container: a website, a database, a bot, monitoring. They do not fight over versions, and you remove one with a single command. Portainer adds a web panel on top, so you see your containers, logs and resources in the browser. This is how we do it. The commands are for Debian/Ubuntu and AlmaLinux/Rocky.
Install Docker
Code: Select all
# Debian / Ubuntu — Docker's official script
curl -fsSL https://get.docker.com | sudo sh
# AlmaLinux / Rocky
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable --now dockerCode: Select all
sudo docker run --rm hello-world
docker compose versiondocker without sudo: sudo usermod -aG docker $USER, then log out and back in. Keep in mind that the docker group is effectively root access, so add only yourself.
Install Portainer
Code: Select all
sudo docker volume create portainer_data
sudo docker run -d --name portainer --restart=always \
-p 127.0.0.1:9443:9443 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:lts127.0.0.1: in front of the port is on purpose: the panel listens only inside the server and cannot be seen from the internet. How to reach it is the next step.sudo docker restart portainer and try again.
Open the panel through an SSH tunnel
From your own computer (Windows 10/11, macOS, Linux):
Code: Select all
ssh -L 9443:localhost:9443 -p PORT user@ssh.vpsstorages.comhttps://localhost:9443 in your browser. The browser will warn about the certificate (Portainer uses its own). Accept it, that is normal. Create the administrator with a long password and choose Get Started → the local environment.This way the panel is protected by your SSH key or password, not only by the Portainer password.
Your first app: a Stack with docker compose
In Portainer: Stacks → Add stack, name it web and paste:
Code: Select all
services:
web:
image: nginx:alpine
ports:
- "127.0.0.1:8080:80"
restart: unless-stoppedCode: Select all
curl -I http://127.0.0.1:8080
Docker bypasses the firewall
This is the most common surprise. A port published as -p 8080:80 is opened by Docker directly in iptables, around ufw/firewalld. So:
- publish ports as
127.0.0.1:PORT:PORTwhen the service is only for you or for a reverse proxy on the same server; - never publish databases (MySQL, PostgreSQL, Redis) to the outside. Containers in one stack see each other by name, without any port;
- check what is really listening:
sudo ss -tlnp.
Updating Portainer
The data lives in the portainer_data volume, so you can replace the container safely:
Code: Select all
sudo docker pull portainer/portainer-ce:lts
sudo docker stop portainer && sudo docker rm portainer
sudo docker run -d --name portainer --restart=always \
-p 127.0.0.1:9443:9443 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:ltssudo docker image prune.
With us it is one tick
When you order a Linux VPS with the Docker or Developer environment, you can pick the free Portainer add-on. The server comes with Docker and Portainer CE, HTTPS only, and the panel opens directly at <name>-panel.vpsstorages.com, no tunnel needed. The login details arrive in the order email.Questions, or your own stacks? Post them here in the topic