Change Port of Service for Docker / Portainer in dynamic configuration file

The automatic configured service for Portainer set port 8000 instead of port 9000 or 9443 into the servers URL (may be by a running chisel-service at port 8000 in the background of Portainer). All documents I found explains that this can be adjusted by setting the label traefik.http.services.<service_name>.loadbalancer.server.port in the docker-compose file.

But the problems are:

  • Portainer has no docker-compose file. It operates with a database.
  • The Portainer locks its own container for modification. Labels can therefore not be added.
  • The automatic update by Watchtower, general from Docker Hub or similar downloads complete images so that also any tricky modification of the image for adding a label makes no really sense.
  • Customized labels in Portainer (with any kind of update-save adjustments) are not supported.

Is there any chance to set the port in the dynamic configuration or the general configuration file of Traefik? Tests in the dynamic configuration like e. g.

[http]
  [http.services]
    [http.services.portainer]
      [http.services.portainer.loadBalancer]
        [[http.services.portainer.loadBalancer.servers]]
          port = 9000

has no effects for portainer@docker but it generates an additional empty portainer@file service. [http.services.portainer.loadBalancer.server] leads to a failure in Traefik.

Portainer can run from docker-compose.yml, here an older Docker Swarm example:

services:
  agent:
    image: portainer/agent:2.16.2
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    networks:
      - agent_network
    deploy:
      mode: global
      placement:
        constraints: [node.platform.os == linux]

  portainer:
    image: portainer/portainer-ce:2.16.2
    command: -H tcp://tasks.agent:9001 --tlsskipverify
    #ports:
    #  - "9443:9443"
    #  - "9000:9000"
    #  - "8000:8000"
    volumes:
      - portainer_data:/data
    networks:
      - proxy
      - agent_network
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]
      labels:
        - traefik.enable=true
        - traefik.http.routers.myportainer.entrypoints=websecure
        - traefik.http.routers.myportainer.rule=Host(`portainer.example.com`)
        - traefik.http.routers.myportainer.tls.certresolver=myresolver
        - traefik.http.services.myportainer.loadbalancer.server.port=9000

networks:
  agent_network:
    driver: overlay
    attachable: true
  proxy:
    external: true

volumes:
  portainer_data: