无法在同一主机上的traefik后面运行多个服务

我有两个服务,如下所示:

version: '3'

services:

  # reverse proxy
  traefik:
    image: traefik:1.7-alpine
    ports:
      - 8080:8080 # access through port 8080 e.g. localhost:8080 -> traefik dashboard
      - 9000:80 # access through port 9000 e.g. localhost:9000 -> actual service (flask and any others)
      - 9001:80 # access through port 9001 e.g. localhost:9001 -> actual service (flask and any others)
      - 443:443 # access through port 443 e.g. localhost:443 -> unused until we get https going
    networks:
      - traefik
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      # - ./acme.json:/acme.json        # ignored for production version
      # - ./traefik.toml:/traefik.toml  # ignored for production version
    container_name: traefik
    command: --docker --api --docker.domain=local.docker
    restart: unless-stopped


  # flask app 1
  flaskapp1:
    # build the Dockerfile
    build:
      context: ./flaskapp1
      dockerfile: Dockerfile
    container_name: flaskapp1
    restart: always
    command: >
      gunicorn -b 0.0.0.0:5000
        --access-logfile -
        --timeout=1200
        --reload
        "flaskapp1.app:create_app()"
    volumes:
      - '.:/flaskapp1'
    networks:
      - traefik
    # exposing a port to the other services (note,this is not publishing the port to the world)
    expose: ['5000']
    # these labels override the traefik configure file so we can setup traefik here,and not deal with a .toml file
    labels:
      - traefik.enable=true
      - traefik.backend=flaskapp1
      - traefik.docker.network=traefik
      - traefik.frontend.rule=Host:localhost
      - traefik.flaskapp1.port=5000



  # flask app 2
  flaskapp2:
    # build the Dockerfile
    build:
      context: ./flaskapp2
      dockerfile: Dockerfile
    container_name: flaskapp2
    restart: always
    command: >
      gunicorn -b 0.0.0.0:5000
        --access-logfile -
        --timeout=600
        --reload
        "hairByElli.app:create_app()"
    volumes:
      - '.:/flaskapp2'
    networks:
      - traefik
    # exposing a port to the other docker services (note,this is not publishing the port to the world)
    expose: ['5000']
    # these labels override the traefik config file so we can setup traefik here,and not deal with a .toml file
    labels:
      - traefik.enable=true
      - traefik.backend=flaskapp2
      - traefik.docker.network=traefik
      - traefik.frontend.rule=Host:localhost:9001
      # - traefik.frontend.rule=Host:localhost;PathPrefixStrip:/app2
      - traefik.flaskapp2.port=5000



networks:
  traefik:
    external: false

如您所见,这是我的localhost测试机。 Ubuntu 18.04。因此,我目前正在尝试以localhost:9000和localhost:9001作为我的切入点,同时让它可以正常工作。

我的flaskapp1完美运行。我的flaskapp2出现404错误。

这是我的toml:

defaultEntryPoints = ["http","https"]

logLevel = "error"
debug = false

# WEB interface of Traefik - it will show web page with overview of frontend and backend configurations
[api]
  dashboard = false
  address = ":8080"

# Connection to docker host system (docker.sock)
[docker]
domain = "local.docker"
watch = true
# This will hide all docker containers that don't have explicitly
# set label to "enable"
exposedbydefault = false


# Force HTTPS
[entryPoints]
  [entryPoints.http]
  address = ":9000"
    [entryPoints.http.redirect]
    entryPoint = "https"

  [entryPoints.http]
  address = ":9001"
    [entryPoints.http.redirect]
    entryPoint = "https"

  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

我在这里做错了什么?我的意思是,我不介意它是否以9000/9001或其他一些切入点出现。只是这样,我可以在同一台计算机上对其进行测试,直到上线为止。此时,我将有单独的域指向它们。

任何帮助将不胜感激。

fwj0830 回答:无法在同一主机上的traefik后面运行多个服务

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3069292.html

大家都在问