Installation of Container Manager Portainer behind Traefik

Set up the container manager Portainer behind Traefik as reverse proxy. Manage your Docker containers conveniently via the web interface from anywhere.

Published on
Installation of Container Manager Portainer behind Traefik hero image

I generally prefer to control my Docker containers directly via my server or use Lazydocker for visual help. However, sometimes (especially on the road) it is also convenient not to have to establish an SSH connection to the server in order to manage certain containers or view the logs. This is where Portainer comes into play.

Portainer | Open Source Container Management GUI for Kubernetes, Docker, Swarm Portainer is the definitive open source container management GUI for Kubernetes, Docker, Swarm and ACI.

Traefik should be set up as a reverse proxy for my configuration file, as described here. Then we need a folder for the data and the Docker-Compose file.

Terminalbash
cd ~/docker
mkdir appdata/portainer/data -p
nano docker-compose-portainer.yml

We add the following text to this file.

yaml
version: "3.7"

### NETWORKS ###
networks:
    web:
        external:
            name: web
    default:
        driver: bridge

### Services ###
services:
    portainer:
        container_name: portainer
        image: portainer/portainer-ce:latest
        restart: unless-stopped
        command: -H unix:///var/run/docker.sock
        networks:
            - web
        security_opt:
            - no-new-privileges:true
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro
            - $DOCKERDIR/appdata/portainer/data:/data
        environment:
            - TZ=$TZ
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.portainer-rtr.entrypoints=https"
            - "traefik.http.routers.portainer-rtr.rule=Host(`portainer.$DOMAINNAME`)"
            - "traefik.http.routers.portainer-rtr.tls=true"
            # - "traefik.http.routers.portainer-rtr.middlewares=chain-basic-auth@file" # Basic Authentication
            - "traefik.http.routers.portainer-rtr.middlewares=chain-oauth@file" # Google Authentication
            - "traefik.http.routers.portainer-rtr.service=portainer-svc"
            - "traefik.http.services.portainer-svc.loadbalancer.server.port=9000"

We use the official image.

Terminalbash
docker-compose -f docker-compose-portainer.yml up -d

Done. Portainer should now be visible under our Portainer subdomain.

An update to a later release can also be carried out very easily.

Terminalbash
docker-compose -f docker-compose-portainer.yml pull
docker-compose -f docker-compose-portainer.yml down
docker-compose -f docker-compose-portainer.yml up -d