gpt4 book ai didi

docker - 无法访问Traefik后面的Docker容器

转载 作者:行者123 更新时间:2023-12-02 21:32:18 45 4
gpt4 key购买 nike

我试图访问在我的远程服务器上运行的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日志均为 infodebug级别,没有出现错误。

最佳答案

我现在没有时间,但是这里有一个快速的代码重写,但未经测试。
这只是一个略有不同的方法。但是我认为这可以达到相同的目标。

  • 您必须包括您的ENV文件
  • traefik.http.routers.api.rule = HostHeader = = Host(`...)。因此很奇怪,也应该与HostHeader一起使用。 Link
  • 现在,有了此基础,您可以对其进行自定义。我使用HTTP chlange,但是使用TLS chlange应该可以。
  • version: "3.7"
    services:
    traefik:
    image: traefik:v2.3.0
    container_name: traefik
    restart: unless-stopped
    env_file:
    - .env
    command: # CLI arguments
    ## Globals
    - "--global.checkNewVersion=false"
    - "--global.sendAnonymousUsage=false"
    ## Entrypoint Settings - https://docs.traefik.io/routing/entrypoints/#configuration ##
    - "--entrypoints.http.address=:80"
    - "--entrypoints.https.address=:443"
    ## API Settings
    - "--api=true"
    - "--api.insecure=false"
    - "--api.dashboard=true"
    - "--log.level=DEBUG" # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
    - "--providers.docker=true"
    - "--providers.docker.exposedByDefault=false"
    ## Certificate Settings
    - "--certificatesresolvers.myresolver.acme.httpchallenge=true"
    - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=http"
    - "--certificatesresolvers.myresolver.acme.email=YOUR-EMAIL@your-domain.com"
    - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    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"
    - "./letsencrypt:/letsencrypt"
    labels:
    - "traefik.enable=true"
    ## HTTP Routers
    - "traefik.http.routers.api.rule=Host(`traefik.${DOMAIN}`)"
    - "traefik.http.routers.api.entrypoints=https"
    - "traefik.http.routers.api.service=api@internal"
    - "traefik.http.routers.api.tls.certresolver=myresolver"
    - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
    - "traefik.http.routers.redirect.rule=hostregexp(`{host:.+}`)"
    - "traefik.http.routers.redirect.middlewares=redirect-to-https"

    whoami:
    image: traefik/whoami
    container_name: simple-service
    networks:
    - frontend
    labels:
    - "traefik.enable=true"
    - "traefik.http.routers.whoami.rule=Host(`whoami.${DOMAIN}`)"
    - "traefik.http.routers.whoami.entrypoints=https"
    - "traefik.http.routers.whoami.tls.certresolver=myresolver"

    networks:
    frontend:
    external: true

    关于docker - 无法访问Traefik后面的Docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64187476/

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