我想构建一个docker景观。我使用一个带有traefik(v2.1)图像的容器和一个用于多个数据库的mysql容器。
traefik / docker-compose.yml
version: "3.3"
services:
traefik:
image: "traefik:v2.1"
container_name: "traefik"
restart: always
command:
- "--log.level=DEBUG"
- "--api=true"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=proxy"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.traefik-dashboard.address=:8080"
- "--certificatesresolvers.devnik-resolver.acme.httpchallenge=true"
- "--certificatesresolvers.devnik-resolver.acme.httpchallenge.entrypoint=web"
#- "--certificatesresolvers.devnik-resolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
- "--certificatesresolvers.devnik-resolver.acme.email=####"
- "--certificatesresolvers.devnik-resolver.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "./data:/etc/traefik"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- "proxy"
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`devnik.dev`)"
- "traefik.http.routers.traefik.entrypoints=traefik-dashboard"
- "traefik.http.routers.traefik.tls.certresolver=devnik-resolver"
#basic auth
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.usersfile=/etc/traefik/.htpasswd"
#Docker Networks
networks:
proxy:
数据库/docker-compose.yml
version: "3.3"
services:
#MySQL Service
mysql:
image: mysql:5.7
container_name: mysql
restart: always
ports:
- "3306:3306"
volumes:
#persist data
- ./mysqldata/:/var/lib/mysql/
- ./init:/docker-entrypoint-initdb.d
networks:
- "mysql"
environment:
MYSQL_ROOT_PASSWORD: ####
TZ: Europe/Berlin
#Docker Networks
networks:
mysql:
driver: bridge
对于结构,我想通过多个docker-compose文件控制所有项目。这些容器应与traefik容器在同一网络上运行,而某些容器应与mysql容器一起运行。这也适用于以下情况(但仅在某些情况下)
dev-releases / docker-compose.yml
version: "3.3"
services:
backend:
image: "registry.gitlab.com/devnik/dev-releases-backend/master:latest"
container_name: "dev-releases-backend"
restart: always
volumes:
#laravel logs
- "./logs/backend:/app/storage/logs"
#cron logs
- "./logs/backend/cron.log:/var/log/cron.log"
labels:
- "traefik.enable=true"
- "traefik.http.routers.dev-releases-backend.rule=Host(`dev-releases.backend.devnik.dev`)"
- "traefik.http.routers.dev-releases-backend.entrypoints=websecure"
- "traefik.http.routers.dev-releases-backend.tls.certresolver=devnik-resolver"
networks:
- proxy
- mysql
environment:
TZ: Europe/Berlin
#Docker Networks
networks:
proxy:
external:
name: "traefik_proxy"
mysql:
external:
name: "database_mysql"
我通过docker-compose up -d
重新启动dev-releases /中的容器时,在浏览器中调用它们时,出现典型错误“网关超时”。一旦我注释了网络networks: #- mysql
并在dev-releases /中重新启动docker-compose,它将再次起作用。
我的猜测是我没有正确配置外部网络。不能使用2个外部网络?我希望某些容器可以访问“ mysql”网络,但是整个traefik网络都不能访问它。
让我知道是否需要更多信息
我让它运行。
我将所有容器都放入一个网络“代理”中。看来mysql也必须在代理网络中。
所以我将以下内容添加到database / docker-compose.yml
networks:
proxy:
external:
name: "traefik_proxy"
并从dev-releases / docker-compose.yml中移出了database_mysql网络>
我想构建一个docker景观。我使用一个带有traefik(v2.1)图像的容器和一个用于多个数据库的mysql容器。 traefik / docker-compose.yml版本:“ 3.3”服务:traefik:...
根据文件名,您的mysql
网络应为mysql_mysql
。您可以通过执行