Help with WebSockets + Traefik + Docker

Hello,

I have a nodejs websockets service. To scale it up and down we are going to use docker containers. But websockets require sticky session and I couldn't get it working with traefik. (It works well with haproxy but it's not really good for us).

Here's my docker-compose.yaml, thanks in advance.

version: '3'

services:
  traefik:
    image: traefik:latest
    command: --web --docker --docker.domain=app.test --logLevel=DEBUG
    ports:
      - 80:80
      - 8080:8080
    networks:
      - mystack_default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.port=8080"
    restart: always
    deploy:
      placement:
        constraints:
            - node.role == manager
  socket:
    ports:
        - 9800:3000
    image: 'umityayla/socket:latest'
    deploy:
        labels:
            - "traefik.port=3000"
            - "traefik.backend=socket"
            - "traefik.backend.loadbalancer.stickiness=true"
            - "traefik.backend.loadbalancer.sticky=true"

networks:
  mystack_default:
    driver: overlay

Hello @umityayla,

at first: you're mixing things up here. You're pulling traefik:latest, which results in you pulling the v1 (therefore, friends to let friends use :latest ;-)).

The labels you're setting are to be used with the v1.7 tough. Can you therefore please pull traefik:1.7.12 and try again? :slight_smile:

unfortunately, still the same.. :confused: and traefik dashboard shows my other containers too, is this normal?

Yeah. exposeByDefault is set to true by default. Therefore its totaly fine to see the other containers. What is the error you're facing?

version: '3'

services:
  traefik:
    image: traefik:v1.7.12
    command: --api --docker --docker.domain=app.test --docker.exposedbydefault=false --logLevel=DEBUG
    ports:
      - 80:80
      - 8080:8080
    networks:
      - mystack_default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.enabale=true"
      - "traefik.port=8080"
    restart: always
    deploy:
      placement:
        constraints:
            - node.role == manager
  socket:
    ports:
        - 9800:3000
    image: 'umityayla/socket:latest'
    deploy:
        labels:
            - "traefik.enabale=true"
            - "traefik.port=3000"
            - "traefik.backend.loadbalancer.stickiness=true"

networks:
  mystack_default:
    driver: overlay

i don't see any errors but, when i use the configuration file you sent; only traefik container is visible in the traefik dashboard.

That is because I've set --docker.exposedbydefault=false in the command for the traefik container.

So when you dont see any errors - what issue are you having exactly?

firstly shouldn't socket service's containers visible in the dashboard?
also sticky connection isn't hapenning. I'm having issues connecting.

If I trust the tags you have put in the topic, you're using swarm.

Then you need to:

  • activate the swarm mode
  • put labels inside the deploy section
version: '3'

services:
  traefik:
    image: traefik:v1.7.12
    command:
      - "--api"
      - "--docker"
      - "--docker.domain=app.test"
      - "--docker.swarmMode=true"
      - "--docker.watch=true"
      - "--docker.exposedbydefault=false"
      - "--logLevel=DEBUG"
    ports:
      - 80:80
      - 8080:8080
    networks:
      - mystack_default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    restart: always
    deploy:
      labels:
        - "traefik.enabale=true"
        - "traefik.port=8080"
      placement:
        constraints:
            - node.role == manager
  socket:
    ports:
      - 9800:3000
    image: 'umityayla/socket:latest'
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.port=3000"
        - "traefik.backend.loadbalancer.stickiness=true"

networks:
  mystack_default:
    driver: overlay

unfortunately, this didn't solve either. but thanks for your help, I guess I'm going to create containers manually and assign ports to them incremental ports (3000,3001,3002) then route them from another haproxy server. thanks again.

I still dont understand the final issue. Did you bound your service (container) to an another entrypoint? Otherwise traefik doesnt know that your service / container needs get websocket traffic proxied to.

traefik.frontend.entryPoints=http,ep-ws

I noticed that you have - "traefik.enabale=true"

im guessing there is a typo in enable.