我目前正在尝试使用Docker Swarm Mode部署一组微服务。我已经建立了一个traefik容器,所有我的容器都是这样的:
version: "3.4"
networks:
backend-network:
external: true
services:
proxy:
image: traefik
command: --api --docker --docker.swarmMode --docker.watch
networks:
- backend-network
ports:
- "80:80"
- "8090:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == manager
front-end:
image: *****
env_file:
- ./env/.react.env
networks: [ "backend-network" ]
ports:
- "8080:80"
deploy:
labels:
- traefik.enable=false
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == manager
users-db:
image: *****
networks: ["backend-network"]
ports: [ "5984:5984" ]
deploy:
labels:
- traefik.enable=false
replicas: 1
restart_policy: # restart if something went wrong
condition: on-failure
# server that listens HTTP requests
users:
image: *****
env_file:
- ./env/.users.env
# wait until service db is up
depends_on: [ "users-db" ]
networks:
- backend-network
# - proxy
# expose port 80 of host node
expose:
- "80"
deploy:
labels:
- traefik.port=80
- traefik.docker.network=backend-network
- traefik.frontend.rule=PathPrefixStrip:/api/auth/
- traefik.backend.loadbalancer.swarm=true
- traefik.backend.loadbalancer.stickiness=true
replicas: 1
shop:
image: *******
env_file:
- ./env/.shop.env
depends_on: [ "users"]
networks:
- backend-network
# - proxy
expose:
- "80"
deploy:
labels:
- traefik.port=80
- traefik.frontend.rule=PathPrefixStrip:/api/shop
- traefik.docker.network=backend-network
- traefik.backend.loadbalancer.swarm=true
- traefik.backend.loadbalancer.stickiness=true
replicas: 1
checkout:
image: *****
env_file:
- ./env/.checkout.env
depends_on: [ "users", "shop" ]
networks:
- backend-network
expose:
- "80"
deploy:
labels:
- traefik.port=80
- traefik.frontend.rule=PathPrefixStrip:/api/checkout
- traefik.docker.network=backend-network
- traefik.backend.loadbalancer.swarm=true
- traefik.backend.loadbalancer.stickiness=true
replicas: 1
visualizer:
image: dockersamples/visualizer:stable
ports: [ "9000:8080" ]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
labels:
- traefik.enable=false
placement:
constraints:
- node.role == manager
我用****隐藏了图像名称。
我在Azure上创建了两个VM,创建了Swarm,Traefik发现了我的服务,但是例如,当我尝试使用azure-dns/api/shop
发出请求时,它总是返回Bad Gateway。
在本地使用docker-compose up
时,效果很好。我还没有在本地使用docker-machine尝试Docker Swarm。我会很快。
答案 0 :(得分:0)
验证backend-network
是一个覆盖网络。
然后先尝试
- traefik.backend.loadbalancer.swarm=true
- traefik.backend.loadbalancer.stickiness=true # especially this one
根据问题3770,粘性会话似乎在v1.7中存在错误。