Networking & Security icon

Put Portainer Behind HTTPS With Caddy (No More Naked IP:9000)

By default Portainer answers on plain http://your-server-ip:9000. Your admin password crosses the network unencrypted, and your browser shows a warning icon every time you open the page. Caddy fixes both. It sits in front of Portainer, gets a real certificate on its own and renews it without a cron job. The whole setup fits in one Compose file.

What you need

  • A server running Docker and Docker Compose. A Pi or a mini PC is plenty
  • A hostname for Portainer, like portainer.yourdomain.com. For home-only use a local name works too, more on that below
  • Ports 80 and 443 free on the host

The Compose file

Both services go in one stack so they share a private network. Portainer no longer publishes port 9000 at all, so the only way in is through Caddy.

services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    networks:
      - proxy

  caddy:
    image: caddy:2
    container_name: caddy
    restart: unless-stopped
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - proxy

networks:
  proxy:

volumes:
  portainer_data:
  caddy_data:
  caddy_config:

The caddy_data volume holds the certificates. Keep it, or Caddy asks for new ones every time you recreate the container.

The Caddyfile

Create a file called Caddyfile next to the Compose file. If the hostname is a real domain that points at your public IP, and ports 80 and 443 are forwarded to this machine, this is all it takes:

portainer.yourdomain.com {
    reverse_proxy portainer:9000
}

Caddy contacts Let’s Encrypt, proves you control the domain and starts serving HTTPS. No certbot, no renewal scripts.

Home only? Use Caddy’s internal CA

If Portainer should never be reachable from the internet, skip the port forwarding and use a local name instead:

portainer.home.lan {
    tls internal
    reverse_proxy portainer:9000
}

The line tls internal makes Caddy issue the certificate from its own private certificate authority. Your browser won’t trust it until you install Caddy’s root certificate on each device. You can copy it out of the container like this:

docker cp caddy:/data/caddy/pki/authorities/local/root.crt .

The traffic is encrypted either way. Point the name at your server in your router, or in Pi-hole’s local DNS settings.

Already running Portainer from the docker run command?

You can keep your data. Stop and remove the old container. The volume stays untouched:

docker stop portainer && docker rm portainer

Then replace the volumes block at the bottom of the Compose file above with one that reuses the existing volume:

volumes:
  portainer_data:
    external: true
  caddy_data:
  caddy_config:

Start the stack:

docker compose up -d

Open https://portainer.yourdomain.com. Your users and stacks should still be there.

When it does not work

  • Caddy can’t get a certificate: for a public domain, DNS has to point at your IP and ports 80 and 443 have to reach this machine. docker compose logs -f caddy shows the exact reason.
  • Port 80 is already allocated: something else is using it. If you followed the Pi-hole guide, Pi-hole’s web interface is the usual culprit. Remap it, for example with -p 8080:80.
  • 502 Bad Gateway: Caddy can’t reach Portainer. Both services must be on the same network, and the Caddyfile must use the service name (portainer), not localhost.
  • Browser warning with tls internal: expected until you trust Caddy’s root certificate on that device.

HTTPS does not make Portainer safe to expose

HTTPS encrypts the connection but doesn’t decide who can log in. Portainer still controls your Docker socket, so everything in the Portainer guide still applies: a strong password, and no open port to the internet unless you really need one. For access from outside, a private VPN is usually a safer choice than a forwarded port.

Related reading

Similar Posts