【发布时间】:2020-10-03 18:14:47
【问题描述】:
我正在尝试访问在我的远程服务器上运行的 whoami 容器,但只能得到“未找到 404 页面”错误。尝试访问 traefik 仪表板时得到相同的结果。
我的 docker-compose.yml:
version: "3.7"
services:
traefik:
image: traefik:v2.3.0
container_name: traefik
restart: unless-stopped
command: # CLI arguments
## Globals
- "--global.checkNewVersion=false"
- "--global.sendAnonymousUsage=false"
## Entrypoint Settings - https://docs.traefik.io/routing/entrypoints/#configuration ##
- "--entrypoints.http.address=:80"
- "--entrypoints.http.http.redirections.entryPoint.to=https"
- "--entrypoints.http.http.redirections.entryPoint.scheme=https"
- "--entrypoints.https.address=:443"
## API Settings
- "--api=true"
- "--api.dashboard=true"
- "--log=true"
- "--log.level=DEBUG" # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
- "--providers.docker=true"
- "--providers.docker.watch=true"
- "--providers.docker.exposedByDefault=false"
## Certificate Settings (Let's Encrypt) - https://docs.traefik.io/https/acme/#configuration-examples ##
- "--certificatesresolvers.mytlschallenge.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory" # TBD - TESTING
networks:
- frontend
ports:
- "80:80"
- "443:443"
- "8080:8080"
security_opt:
- "no-new-privileges:true" # https://docs.docker.com/engine/reference/run/#security-configuration
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "$USERDIR/ctmp/acme/acme.json:/acme.json:rw" # cert location - you must touch this file and change permissions to 600
labels:
- "traefik.enable=true"
## HTTP Routers
- "traefik.http.routers.traefik-rtr.rule=HostHeader(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik-rtr.entrypoints=https"
- "traefik.http.routers.traefik-rtr.service=api@internal"
whoami:
image: "traefik/whoami"
container_name: "simple-service"
networks:
- frontend
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=HostHeader(`whoami.${DOMAIN}`)"
- "traefik.http.routers.whoami.entrypoints=http"
networks:
frontend:
external: true
$USERDIR 和 $DOMAIN 在我的 .env 文件中定义。
所有的traefik日志都是info或debug级别,没有出现错误。
【问题讨论】:
-
curl -s 127.0.0.1:8080/api/rawdata | jq .的输出是什么?看到 traefik whoami 容器了吗?您可能需要一个 JSON 格式化程序“apt install jq” -
运行该命令时(通过 SSH 登录到远程服务器),我没有得到任何输出。
-
好的,这应该是 Traefik 的回应。
-
为什么我应该在 localhost 上看到一些东西?我希望它从公共 IP 地址路由到内部 docker 网络 IP 地址。
-
不,这只是你的例子,你当然必须
curl -s https://traefik.your-domain.com/api/rawdata | jq .你的 Traefik 静态配置中有什么,所以你有一个?
标签: docker docker-compose traefik