How to maintain a sticky session (session persistence) with docker?

I have one Java based web application that is being deployed to jboss-10.1.0(wildfly). I use docker version 1.12.1to scale my application, everything works fine, but the only problem I encountered is session management.

Now let's look at the scenario.

I have two instances for my application (i.e. App1and App2). I use the default load balancer provided by docker roaming mode with c nginxto redirect my application from chintan.test.com:9080to chintan.test.com:80so I don’t need to write a port with my URL and I can directly access this URL chintan.test.com.

The default load balancer now uses RR ( Round-Robin algorithm) to serve my web request. So the first time I visit chintan.test.com, it goes to the instance App1and displays the login page that I enter with the credentials, and everything works fine, after a few minutes it will switch to App2and the login page will appear again.

Is there a way or tools (should there be Open-source) through which I process sessions? Therefore, at least I log into the system App1and stick App1until I log out of the system.

Thank!

+4
source share
2 answers

Docker swarm , round robin - .

, - , ( , DNS , ). , , .

+1

Nginx HA-Proxy, SWARM. Traefik Docker Swarm, . , Traefik node, . , , ..

Docker compose version 3, Docker.

docker-compose.yml( 3) Traefik Image.

   loadbalancer:
image: traefik
command: --docker \
  --docker.swarmmode \
  --docker.watch \
  --web \
  --loglevel=DEBUG
ports:
  - 80:80
  - 9090:8080
volumes:
  - /var/run/docker.sock:/var/run/docker.sock
deploy:
  restart_policy:
    condition: any
  mode: replicated
  replicas: 1
  update_config:
    delay: 2s
  placement:
     constraints: [node.role == manager]

,

whoami:
image: tutum/hello-world
networks:
  - net
ports:
  - "80"
deploy:
  restart_policy:
    condition: any
  mode: replicated
  replicas: 5
  placement:
    constraints: [node.role == worker]
  update_config:
    delay: 2s
  labels:
    - "traefik.docker.network=test_net"
    - "traefik.port=80"
    - "traefik.frontend.rule=PathPrefix:/hello;"
    - "traefik.backend.loadbalancer.sticky=true"

.

+1

Source: https://habr.com/ru/post/1674730/


All Articles