docker - 一台主机上有两个带有 Traefik 的 docker 容器
问题描述
我正在尝试在我的树莓派上设置一个服务器来运行 Nextcloud 和 Firefly III,并使用 traefik 作为反向代理。我正在使用 docker-compose 并且 Portainer 在 https 上运行良好(包含在测试代码中),但我根本无法让 Nextcloud 或 Firefly 运行。当我使用 Firefly 的官方文档时,我可以让它运行,当我使用 NextcloudPi 本身时,我也可以让它运行,但我不能让它们同时工作。FF 给出了 403 Forbidden “您无权访问此服务器上的 / ”。Nextcloud 给出“Bad Gateway”错误时出错。我会很感激我能得到的任何帮助,因为我已经阅读了尽可能多的网站,而且我不知道还有什么可做的。
这是我的 docker-compose.yml:
version: "3.2"
services:
# Reverse Proxy and Let's Encrypt
traefik:
container_name: traefik
image: traefik:alpine
restart: always
networks:
- srv
- firefly_iii_net
- proxy-tier
ports:
- 80:80
- 443:443
volumes:
- /opt/traefik/traefik.toml:/traefik.toml
- /var/run/docker.sock:/var/run/docker.sock
- /opt/traefik/acme.json:/acme.json
# Portainer
portainer:
container_name: portainer
image: portainer/portainer
restart: always
networks:
- srv
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/portainer:/data
labels:
- traefik.enable=true
- "traefik.frontend.rule=Host:port.skdjfgsl.club"
db:
image: postgres:alpine
restart: always
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
app:
image: nextcloud:fpm-alpine
restart: always
volumes:
- nextcloud:/var/www/html
environment:
- POSTGRES_HOST=db
- POSTGRES_PASSWORD=
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
depends_on:
- db
networks:
- proxy-tier
expose:
- 80
- 443
labels:
- traefik.enable=true
- "traefik.frontend.rule=Host:nc.skdjfgsl.club"
firefly_iii_app:
environment:
- FF_DB_HOST=firefly_iii_db
- FF_DB_NAME=firefly
- FF_DB_USER=firefly
- FF_DB_PASSWORD=firefly
- FF_APP_KEY=S0m3R@nd0mStr1ngOf32Ch@rsEx@ctly
- FF_APP_ENV=local
- FF_DB_CONNECTION=pgsql
- TZ=Europe/Amsterdam
- APP_LOG_LEVEL=debug
- TRUSTED_PROXIES=**
image: jc5x/firefly-iii
links:
- firefly_iii_db
networks:
- firefly_iii_net
volumes:
-
source: firefly_iii_export
target: /var/www/firefly-iii/storage/export
type: volume
-
source: firefly_iii_upload
target: /var/www/firefly-iii/storage/upload
type: volume
expose:
- 80
- 443
labels:
- traefik.enable=true
- "traefik.frontend.rule=Host:ff.skdjfgsl.club"
- traefik.port=443
firefly_iii_db:
environment:
- POSTGRES_PASSWORD=firefly
- POSTGRES_USER=firefly
image: "postgres:10"
networks:
- firefly_iii_net
volumes:
- "firefly_iii_db:/var/lib/postgresql/data"
networks:
srv:
firefly_iii_net:
driver: bridge
proxy-tier:
volumes:
db:
nextcloud:
firefly_iii_db: ~
firefly_iii_export: ~
firefly_iii_upload: ~
这是我的 traefik.toml:
defaultEntryPoints = ["http", "https"]
logLevel = "DEBUG"
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "mydomain.com"
exposedByDefault = false
watch = true
[acme]
email = "email@mydomain.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
解决方案
要访问端口 443 (https),您需要调整 traefik 使用的协议以与具有以下标签的容器通信:
- traefik.protocol=https
错误的网关可能意味着 traefik 试图连接到错误的端口、错误的 IP 或 traefik 并且容器未部署到公共网络。您可以通过指定端口和网络名称来修复前两个:
- traefik.port=80
- traefik.docker.network=project_proxy-tier
其中 project 是您的撰写项目的名称(用于docker network ls
查看网络的外部名称)。
推荐阅读
- macos - CoreGraphics:如果图像被缩放,绘制 NSImage 的性能会受到影响
- java - 在 Java 上的一个线程中等待多个事件
- r - R将两个列表合并为一个,从每个列表中交替绘制元素
- r - dplyr:评估名称在向量中的变量的总和
- ios - NSURLSession 完成处理程序意味着如果 didReceiveChallenge 被自动调用
- java - Spring批处理分区,多个步骤按顺序运行?
- html - 着色父菜单点
- c# - 尝试从 Cosmos DB 中删除时找不到资源
- entity-framework - 实体框架通过变量名获取表
- javascript - vue 和 sockert 错误 - 当请求的凭据模式为“包含”时,响应不能是通配符“*”