我试图用traefik在dockers-swarm上实现粘性会话,但是我无法在同一台计算机上的两个副本上实现会话持久性。 在我的docker-compose.yml中,我添加了traefik的标签,还添加了loadbalancer。下面是我的docker-compose.yml,(虽然缩进在这里看起来不正确,但在实际项目中正确)
version: '3'
services:
web:
image: php:7.2.11-apache-stretch
ports:
- "8080:80"
volumes:
- ./code/:/var/www/html/hello/
stdin_open: true
tty: true
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: any
update_config:
delay: 2s
labels:
- "traefik.docker.network=docker-test_privnet"
- "traefik.port=80"
- "traefik.backend.loadbalancer.sticky=true"
- "traefik.frontend.rule=PathPrefix:/hello"
networks:
- privnet
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]
networks:
- privnet
networks:
privnet:
external: true
我想念什么吗?
答案 0 :(得分:2)
几件事。
.sticky
是deprecated赞成traefik.backend.loadbalancer.stickiness=true
traefik.docker.network
来设置网络。-c
和-b
。