0

I've faced with a problem in Traeifk:2 and Docker swarm I want to Implement my reverse proxy with Traefik2 using DockerSwarm

I have 3 machines (in Virtualbox)

  • master.ox # My DockerSwarm Leader
  • worker1.ox # Worker1
  • worker2.ox # Worker2

this is my "/etc/hosts" file

192.168.56.101  master.ox traefik.master.ox hello.master.ox
192.168.56.102  worker1
192.168.56.103  worker2

I've done this steps

in master.ox (initializing the swarm leader):

  docker swarm init --advertise-addr 192.168.56.101
  docker network create --driver overlay my-net

and in worker1 and worker2 (joining to the swarm):

docker swarm join --token SWMTKN-1-2jcok5sisa5kohn1nqqwpnasnj3t7hs7vs7c1cellf1eloyja6-16mnbgywkbpc5ssccw5anu0to 192.168.56.101:2377

I set label "category=service" for worker1 and worker2 with command

docker node update --label-add=category=service worker1
docker node update --label-add=category=service worker2

this is my docker-compose file:

version: "3.3"
        
networks: 
  my-net:
    external: true

services:
  nginx: 
    image: nginxdemos/hello
    networks: 
      - my-net
    deploy: 
      labels: 
        - "traefik.enable=true"
        - "traefik.docker.network=my-net"
        - "traefik.http.services.nginx.loadbalancer.server.port=80"
        - "traefik.http.routers.nginx.entrypoints=http"
        - "traefik.http.routers.nginx.service=nginx"
        - "traefik.http.routers.nginx.rule=Host(`hello.master.ox`)"
      placement:
        constraints:
          - node.labels.category==service

  traefik: 
    image: traefik:latest
    ports: 
      - 8080:8080
      - 80:80
    command: 
      - "--log.level=DEBUG"
      - "--providers.docker"
      - "--providers.docker.swarmmode=true"
      - "--providers.docker.network=my-net"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.exposedbydefault=false"
      - "--api=true"
      - "--ping=true"
      - "--api.insecure=true"
      - "--api.dashboard=true"
      - "--entrypoints.http.address=:80"
      - "--entrypoints.https.address=:443"
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    networks: 
      - my-net
    deploy: 
      mode: global
      labels: 
        - "traefik.enable=true"
        - "traefik.docker.network=my-net"
        - "traefik.http.services.traefik.loadbalancer.server.port=8080"
        - "traefik.http.routers.traefik.entrypoints=http"     
        - "traefik.http.routers.traefik.service=api@internal"
        - "traefik.http.routers.traefik.rule=Host(`traefik.master.ox`)"
      placement:
        constraints:
          - node.role == manager

but it's not worked as I excepted :( I receive "Bad Gateway" from "hello.master.ox"

Could you help me :)

I expected by visiting "hello.master.ox", i receive nginx result, but I viewed "Bad Gateway" Error

  • I found that I should add docker swarm ports to the firewall on the both manager node and client node https://www.digitalocean.com/community/tutorials/how-to-configure-the-linux-firewall-for-docker-swarm-on-centos-7 – Amir.Ojvar Jun 20 '23 at 05:53
  • can you post the log of traefik? – David Jun 23 '23 at 14:54

1 Answers1

0

I solved the problem I should add docker swarm ports to firewall on the both manager-node and client-nodes

https://www.digitalocean.com/community/tutorials/how-to-configure-the-linux-firewall-for-docker-swarm-on-centos-7

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '23 at 09:52