gpt4 book ai didi

docker - Traefik v2不使用路径进行路由,而是使用ip

转载 作者:行者123 更新时间:2023-12-02 19:51:26 25 4
gpt4 key购买 nike

我有3个VM机器在docker群中运行,当我在一个VM机器上构建docker-compose文件时,我的docker-compose文件可以完美运行,但是当我部署堆栈并希望以群模式工作时,Traefik会检测到容器和服务,但路由器会不适用于我在docker-compose文件中提到的路径。
这是我的docker-compose文件:

    version: "3"

volumes:
prometheus_data: {}

services:
joomla:
image: erfanemoon/joomla_img
hostname: joomla
ports:
- 8081:80
#- 81:81
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
labels:
- "traefik.enable=true"
- "traefik.http.routers.joomla.rule=Host(`joomla.localhost`)"
- "traefik.http.routers.joomla.priority=49"
- "traefik.http.routers.joomla.entrypoints=web"
#- "traefik.http.services.joomla.loadbalancer.server.port=80"
entrypoint: ["wait-for-it.sh", "-t", "120", "db:3306", "--", "docker-php-entrypoint", "-D FOREGROUND"]
depends_on:
- db
volumes:
- /gfs/joomla/:/var/www/html/
networks:
- intnet
#- extnet
pmy:
image: phpmyadmin/phpmyadmin
hostname: pmy
depends_on:
- db
ports:
- 8082:80
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
labels:
- "traefik.enable=true"
- "traefik.http.routers.pmy.rule=Host(`pmy.localhost`)"
- "traefik.http.routers.pmy.priority=50"
- "traefik.http.routers.pmy.entrypoints=web"
- "traefik.http.services.pmy.loadbalancer.server.port=80"
environment:
DB_HOST: db
MYSQL_ROOT_PASSWORD: qweasd
volumes:
- /gfs/phpmyadmin:/config
networks:
- intnet
#- extnet

db:
image: mariadb
command: --default-authentication-plugin=mysql_native_password
hostname: db
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: qweasd
volumes:
- /gfs/mysql:/var/lib/mysql
networks:
- intnet
#- extnet


traefik:
image: "traefik:v2.0.0-rc3"
hostname: traefik
command:
- "--api=true"
- "--api.debug=true"
- "--api.insecure=true"
#- --providers.docker=true
#- --traefik.http.routers.traefik.rule=Host(`traefik.localhsot`)
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--providers.docker.swarmMode=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=app_intnet"
#- --providers.docker.network=app_extnet
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
#- /home/erfan/joomla/data/traefik.yml:/traefik.yml:ro
#- /home/erfan/joomla/data/acme.json:/acme.json
deploy:
placement:
constraints:
- node.role == manager
networks:
- intnet
- extnet
networks:
intnet:
internal: true
driver: overlay
ipam:
driver: default
config:
- subnet: 192.168.200.0/24
extnet:
driver: overlay
#external: true
ipam:
driver: default
config:
- subnet: 192.168.100.0/24

这些是docker网络:
     NETWORK ID          NAME                DRIVER              SCOPE
ukzzfno60hbc app_extnet overlay swarm
qtj33re0udg1 app_intnet overlay swarm
7a29fd57a6e7 bridge bridge local
01595efaa286 docker_gwbridge bridge local
96be2c7598cf host host local
26migzlan45q ingress overlay swarm
b54bbc08d908 none null local

当我输入:
joomla.localhost或pmy.localhost,它不会打开页面,但是当我输入IP地址时,它仍在工作,而且我不知道为什么会发生,如果有人可以帮助我,我会很高兴

最佳答案

您缺少服务中的以下标签

- traefik.docker.network=intnet

这是将Traefik与Docker Swarm结合使用的完整示例,在此 post中也可以找到更多信息
version: '3.7'

networks:
traefik:
external: true

volumes:
db_data:

services:

proxy:
image: traefik:v2.1
command:
- '--providers.docker=true'
- '--entryPoints.web.address=:80'
- '--providers.providersThrottleDuration=2s'
- '--providers.docker.watch=true'
- '--providers.docker.swarmMode=true'
- '--providers.docker.swarmModeRefreshSeconds=15s'
- '--providers.docker.exposedbydefault=false'
- '--providers.docker.defaultRule=Host("local.me")'
- '--accessLog.bufferingSize=0'
- '--api=true'
- '--api.dashboard=true'
- '--api.insecure=true'
- '--ping.entryPoint=web'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
ports:
- '80:80'
- '8080:8080'
deploy:
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
update_config:
delay: 10s
order: start-first
parallelism: 1
rollback_config:
parallelism: 0
order: stop-first
logging:
driver: json-file
options:
'max-size': '10m'
'max-file': '5'
networks:
- traefik

mysql:
image: mysql:5.7
command: mysqld --general-log=1 --general-log-file=/var/log/mysql/general-log.log
deploy:
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
update_config:
delay: 10s
order: start-first
parallelism: 1
rollback_config:
parallelism: 0
order: stop-first
logging:
driver: json-file
options:
'max-size': '10m'
'max-file': '5'
networks:
- traefik
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: dummy
MYSQL_DATABASE: rails_blog_production

rails_blog_web:
image: wshihadeh/rails_blog:demo-v1
command: 'web'
deploy:
labels:
- traefik.enable=true
- traefik.http.services.blog.loadbalancer.server.port=8080
- traefik.http.routers.blog.rule=Host(`blog.local.me`)
- traefik.http.routers.blog.service=blog
- traefik.http.routers.blog.entrypoints=web
- traefik.docker.network=traefik
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
update_config:
delay: 10s
order: start-first
parallelism: 1
rollback_config:
parallelism: 0
order: stop-first
logging:
driver: json-file
options:
'max-size': '10m'
'max-file': '5'
networks:
- traefik
depends_on:
- mysql
environment:
DATABASE_URL: mysql2://root:dummy@mysql/rails_blog_production
RAILS_SERVE_STATIC_FILES: 'true'

关于docker - Traefik v2不使用路径进行路由,而是使用ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60478053/

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