gpt4 book ai didi

amazon-web-services - 在AWS上使用Docker服务设置traefik

转载 作者:行者123 更新时间:2023-12-02 18:30:28 25 4
gpt4 key购买 nike

我正在尝试在我的docker服务中使用traefik(尽管仅以1个docker服务开始),我已经能够设置traefik,但是它忽略了我包含在docker compose文件中的标签。我在AWS上使用了docker swarm。

日志表明"Filtering container without port and no traefik.port label service_myapp.3"
我已经使用docker service inspectdocker container inspect检查了服务和容器,并显示了标签。

traefik Web控制台显示一个docker选项卡,但其下没有任何内容。

这是我的traefik.toml

logLevel = "DEBUG"
traefikLogsFile = "/var/logs/traefik.log"

[entryPoints]
[entryPoints.http]
address = ":80"
[web]
address = ":8080"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "docker.localhost"
watch = true
swarmmode = true
exposedbydefault = false

这是我的docker compose yml
version: "3.4"
configs:
traefik:
external:
name: traefik
services:
traefik:
image: traefik:1.3.5
configs:
- source: traefik
target: /etc/traefik/traefik.toml
mode: 0400
depends_on:
- myapp
volumes:
- traefiklogs:/var/logs
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 80:80
- 443:443
- 8080:8080
networks:
- public
- private
tty: true
deploy:
mode: global
placement:
constraints:
- node.role == manager
myapp:
image: myapp
deploy:
endpoint_mode: vip
replicas: 3
restart_policy:
condition: on-failure
ports:
- "4000:8080"
networks:
- public
- private
labels:
traefik.frontend.rule: "Host:myapp.myapp.com"
traefik.backend: "myapp"
traefik.docker.network=: "public"
traefik.enable: "true"
traefik.port: "4000"
networks:
public:
driver_opts:
encrypted: 1
private:
driver_opts:
encrypted: 1
volumes:
sqldata:
traefiklogs:

最佳答案

使用swarmmode = true,您需要在服务而不是容器上设置标签。这是通过在deploy部分中定义标签来完成的:

version: "3.4"
configs:
traefik:
external:
name: traefik
services:
traefik:
image: traefik:1.3.5
configs:
- source: traefik
target: /etc/traefik/traefik.toml
mode: 0400
depends_on:
- myapp
volumes:
- traefiklogs:/var/logs
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 80:80
- 443:443
- 8080:8080
networks:
- public
- private
tty: true
deploy:
mode: global
placement:
constraints:
- node.role == manager
myapp:
image: myapp
deploy:
endpoint_mode: vip
replicas: 3
restart_policy:
condition: on-failure
labels:
traefik.frontend.rule: "Host:myapp.myapp.com"
traefik.backend: "myapp"
traefik.docker.network=: "public"
traefik.enable: "true"
traefik.port: "4000"
ports:
- "4000:8080"
networks:
- public
- private
networks:
public:
driver_opts:
encrypted: 1
private:
driver_opts:
encrypted: 1
volumes:
sqldata:
traefiklogs:

关于amazon-web-services - 在AWS上使用Docker服务设置traefik,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48069300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com