我正在尝试建立一个基本系统,其中traefik容器用作后端nodejs服务器的反向代理。 Traefik放在自己的容器中,nodejs也有一个容器。这里的目标是通过在群模式下使用docker来更新nodejs服务而不会造成任何停机。这是我的compose和traefik.yml文件的以下配置,但似乎无法访问localhost:8080或nodejs服务器上的traefik仪表板。
nodejs服务器在端口9200上运行。看一下现有的堆栈溢出答案,它们几乎与下面的配置相同。我在这里想念东西吗?
compose.yml
version: "3.7"
services:
api:
image: example/hobby:v1
deploy:
replicas: 1
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
window: 120s
rollback_config:
parallelism: 1
delay: 20s
order: stop-first
update_config:
parallelism: 1
delay: 15s
failure_action: rollback
order: stop-first
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`localhost`)"
- "traefik.http.routers.api.entrypoints=insecure"
# - "traefik.http.routers.api.service=api"
- "traefik.http.services.api.loadbalancer.server.port=9200"
placement:
constraints:
- node.role == worker
env_file:
- ./.env
networks:
- verse
reverse-proxy:
image: traefik:v2.3
deploy:
mode: global
labels:
# - "traefik.http.routers.reverse-proxy.middlewares=auth"
- "traefik.enable=true"
- "traefik.http.routers.api.entrypoints=insecure"
- "traefik.http.routers.api.rule=Host(`localhost`)"
placement:
constraints: [node.role==manager]
# ports:
# - target: 80
# published: 80
# mode: host
# - target: 8080
# published: 8080
# mode: host
networks:
- verse
ports:
- "80:80"
- "8080:8080" # traefik dashboard
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
# - "/var/run/docker.sock:/var/run/docker.sock"
- ./traefik.yml:/etc/traefik/traefik.yml
networks:
verse:
# driver: overlay
external: false
traefik.yml
entryPoints:
insecure:
address: ":80"
traefik:
address: ":8080"
log:
level: DEBUG
# filePath: /path/to/log-file.log
format: json
api:
# insecure: true
dashboard: true
debug: true
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
swarmMode: true
watch: true
network: verse
middlewares:
auth:
basicAuth:
users:
- "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"