Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4715

Docker + HAProxy + WebSockets

$
0
0

@umityayla wrote:

Hello,

We have a node.js websockets service. Due to node.js being singlethread, we are going to create many containers in a server just for sockets. So we decided to turn it into a service but we can’t configure sticky connection. Is there any example that we could do that? (Just to be clear, haproxy will redirect connections to different containers, not to different servers.Also we are going to have more than one host)
Our current docker-compose.yaml but it doesn’t really suceed the sticky connection.

version: '3'

services:

  proxy:
    image: dockercloud/haproxy
    # Won't start until at least one of our app services is up and running.
    depends_on:
      - socket
    environment:
      # The type of load balancing strategy that will be used.
      # - leastconn sends request to the service with the least active requests.
      # - roundrobin rotates the requests around the services.
      - COOKIE = rewrite nocache 
      # Used to identify services.
      - ADDITIONAL_SERVICES=project_dir:socket
    volumes:
      # Since our app services are running on the same port,
      # the HAProxy will use the docker.sock to find the
      # services that it should load balance.
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      # The internal used by the HAProxy is 80,
      # but we can expose any port that we would like externally.
      # For example, if you are running something else on 80,
      # you probably don't want to expose the HAProxy on 80 as well.
      - 12001:80
    networks:
      - web
    deploy:
      # The HAProxy is assigned as the manager.
      placement:
        constraints: [node.role == manager]

  socket:
    environment:
        - SERVICE_PORTS=9800
    ports:
        - 9800:3000
    image: 'umityayla/socket:latest'
    networks:
        - web

networks:
  web:
    driver: overlay

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>