Portainer 502 after reboot

I deployed portainer with the following docker-compose.yml:

version: '2'

networks:
  web:
    external: true

services:
  portainer:
    image: portainer/portainer
    container_name: portainer
    command: -H unix:///var/run/docker.sock
    ports:
     - 9000
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    networks:
      - web
    labels:
      - traefik.enable=true
      - traefik.basic.protocol=http
      - traefik.docker.network=web
      - traefik.backend=portainer
      - traefik.frontend.rule=Host:portainer.mydomain.ca
      - traefik.port=9000

volumes:
  portainer_data:
    external: true

It has worked fine along with my other services fronted by Traefik.

After my server rebooted I now get a 502 bad gateway at portainer.mydomain.ca

The container is running, it is attached to the 'web' network, and its logs show it is listening on :9000.

In Traefik's web interface, the frontends and backends are listed, backed has the correct container ip address and port.

Anyone clue me in as to why this would stop working?

Hi @VinistoisR, can you switch from ports to expose on the docker-compose file of your portainer?

Using the directive ports means that Docker will publish the port to the outside network, which you don't want. If you use expose, Traefik will still be able to pick the ports and IP, and every requests "Traefik <-> Portainer" will stay inside the Docker private network named web.

Not 100% sure if it will solve your issue, as it could be tons of others causes.

If the error 502 persists, can you do the following:

  • Reports here the full configuration for both Traefik and Portainer
  • Reports here the result of the commands docker inspect <Container ID> for both containers traefik and portainers, so we can check if Docker messed up anything during the reboot?
  • Try to create a container attached to the web network, and run a verbose curl request to portainer?
$ docker run --rm -ti --network=web alpine:3.10 sh
#/ apk add --no-cache curl # Install curl
...
#/ curl --verbose --location --silent http://<IP of portainer container>:9000/