When to use this stack
Portainer Community Edition is a web interface for Docker. It lists containers, images, networks and volumes, shows logs, opens a console into a container and lets you deploy Compose stacks from a browser. This stack runs Portainer on one host, stores its settings in a named volume, and binds its HTTPS port to localhost so the panel is not visible on the public network.
Use this stack when you manage a single Docker host and you want a visual overview for start, stop and log tasks, or when team members need a web view without SSH access. It is a good choice for a home lab or a small VPS where you run several stacks. Do not use it as a public service, and do not use it on a machine where you cannot restrict who reaches the port. Do not give it to people who should only read logs, because every Portainer user with the right role can change containers, and anyone with control of the Docker socket can gain root on the host. For many hosts, the Portainer agent is the better design, which is covered in the variations.
docker-compose.yml
services:
portainer:
image: portainer/portainer-ce:2.21.4
restart: unless-stopped
ports:
- "127.0.0.1:${PORTAINER_HTTPS_PORT}:9443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
volumes:
portainer_data:# Host port for the HTTPS web UI. It is bound to 127.0.0.1 in docker-compose.yml.
PORTAINER_HTTPS_PORT=9443.env
# Host port for the HTTPS web UI. It is bound to 127.0.0.1 in docker-compose.yml.
PORTAINER_HTTPS_PORT=9443Start and verify
# Save the blocks above as docker-compose.yml and .env in one folder
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=30 portainer
# The port is bound to localhost only, so check it from the server
curl -k -s -o /dev/null -w "%{http_code}\n" https://127.0.0.1:9443
# From your own computer, open an SSH tunnel and browse to it
# ssh -L 9443:127.0.0.1:9443 youruser@your-server
# then open https://localhost:9443 in your browserOpen the URL within five minutes and create the administrator account with a long, unique password. The first login also asks which environment to manage; choose the local Docker environment.
Production checklist
- Keep the port bound to 127.0.0.1 and reach it only through an SSH tunnel or an HTTPS reverse proxy with access control. Never publish 9443 on 0.0.0.0.
- Create the admin account immediately after the first start, since the setup window closes when it is left idle.
- Treat every Portainer administrator as root on the host. The socket mount gives the container control over the Docker daemon, and the daemon can start a privileged container that reads the whole filesystem.
- Create separate users with the least privilege they need instead of sharing the admin login.
- Do not mount the Docker socket into other containers, and do not add extra host mounts to this stack.
- Pin portainer/portainer-ce to a specific 2.x tag and upgrade on purpose after checking the release notes.
- Back up the portainer_data volume, since it stores users, settings and stack definitions.
- Keep the host firewall closed for port 9443 and allow only SSH and your web ports.
Common problems
- Symptom: “Your Portainer instance timed out for security purposes.” Cause: No admin account was created in the setup window. Fix: Run
docker compose restart portainer, then open the page and create the account at once. - Symptom: The browser shows a certificate warning on https://localhost:9443. Cause: Portainer uses a self-signed certificate by default. Fix: Accept it for the SSH tunnel, or put Portainer behind Caddy or Traefik with a trusted certificate.
- Symptom: The local environment shows as unreachable or has no containers. Cause: The socket path is missing from the volumes, or the host uses a different socket location. Fix: Check
docker compose exec portainer ls -l /var/run/docker.sockand confirm the mount line. - Symptom: Compose fails with “port is already allocated”. Cause: Another service uses the chosen port. Fix: Change PORTAINER_HTTPS_PORT in .env and run
docker compose up -dagain. - Symptom: Users, stacks and settings disappear after a recreate. Cause: The volume was removed with
docker compose down -v. Fix: Restore a backup of portainer_data, and avoid the -v flag in routine maintenance.
Variations
- Portainer Agent for several hosts: Run the portainer/agent container on each remote host, expose its port only over a private network or VPN, and add those endpoints from the main Portainer instance.
- Behind Caddy: Put a
reverse_proxy https://portainer:9443route withtransport http { tls_insecure_skip_verify }in front of the UI so it gets a trusted certificate, and publish only the proxy. - Limited Docker API: Route Portainer through a socket proxy that allows only the endpoints you need. Some Portainer features stop working, so test each workflow after you restrict the API.
Questions
Is Portainer safe to run on a server?
It is safe when only administrators can reach it, over an SSH tunnel or HTTPS behind a proxy. It mounts the Docker socket, so anyone who logs in to Portainer controls the host.
Why does Portainer say the setup timed out?
Portainer closes the initial setup if no admin account is created within about five minutes. Restart the container with docker compose restart portainer and create the account right away.
Do I need to publish port 9443 to the internet?
No. This stack binds it to 127.0.0.1, so you reach it through an SSH tunnel or a reverse proxy that you protect with HTTPS.
Will I lose my settings if I update the image?
No, as long as you keep the portainer_data volume. Never run docker compose down -v, because that deletes the named volume.
Adapt this stack
Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.
Open in builderRelated stacks
Caddy 2 Reverse Proxy + Static Web Server
Caddy 2 in Docker Compose: serve a static site, proxy /api to a backend and get automatic HTTPS on a real domain. Pinned images and .env configuration.
Gitea Git Server with PostgreSQL 16
Self-hosted Gitea with PostgreSQL 16 in Docker Compose: web Git hosting, SSH on port 2222, a healthcheck-gated database start and persistent volumes.
Loki, Promtail and Grafana Log Stack
Collect Linux host logs with Loki and Promtail in Docker Compose and query them in Grafana. Pinned images, persistent volumes and a localhost-only Grafana port.
Prometheus + Grafana + Node Exporter
Monitor a Linux host with Prometheus, Node Exporter and Grafana in Docker Compose. Pinned images, .env secrets, retention settings and localhost-only ports.
Browse more Infrastructure & Monitoring stacks or the full library.