一主机多容器,根据路径切换容器

One host for multiple containers and switch container based on the path

我使用 traefik 和 docker 后端。这是我启动 traefik 的方式:

$ cat docker-compose.yml
version: '2'

networks:
  default:
    external:
      name: proxy

services:
  traefik:
    image: traefik
    command: --web --docker --docker.domain=docker --logLevel=WARNING
    container_name: traefik
    ports:
      - "80:80"
      - "8080:8080"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
    labels:
      - "traefik.frontend.rule=Host:dashboard.docker"
      - "traefik.port=8080"

我想要 2 个容器,一个是 docker registry, and a second one is a UI for the registry。我希望像 registry.docker/v2/* 这样的所有 HTTP 请求都通过注册表容器,但任何其他请求(registry.docker/registry.docker/repositories/20、...)都通过 UI 容器。

这是我试过的:

$ cat docker-compose.yml
version: '2'

networks:
  default:
    external:
      name: proxy

services:
  registry:
    image: registry:2
    container_name: registry
    environment:
      -  REGISTRY_STORAGE_DELETE_ENABLED=true
    labels:
      - traefik.frontend.rule=Host:registry.docker, PathPrefix:/v2
      - traefik.frontend.port=5000

  registry-ui:
    image: konradkleine/docker-registry-frontend:v2
    container_name: registry-ui
    environment:
      - ENV_DOCKER_REGISTRY_HOST=registry.docker
      - ENV_DOCKER_REGISTRY_PORT=80
      - ENV_DOCKER_REGISTRY_USE_SSL=false
    labels:
      - traefik.frontend.rule=Host:registry.docker

但是所有请求都通过 registry 容器。我应该改变什么?

我认为你这里有错字,根据我的文件,这是一个可能的解决方案

试试这个:

version: '2'

networks:
  default:
    external:
      name: proxy

services:
  registry:
    image: registry:2
    container_name: registry
    environment:
      -  REGISTRY_STORAGE_DELETE_ENABLED=true
    labels:
      - traefik.frontend.rule: Host:registry.docker;PathPrefix:/v2
      - traefik.frontend.port: 5000

  registry-ui:
    image: konradkleine/docker-registry-frontend:v2
    container_name: registry-ui
    environment:
      - ENV_DOCKER_REGISTRY_HOST=registry.docker
      - ENV_DOCKER_REGISTRY_PORT=80
      - ENV_DOCKER_REGISTRY_USE_SSL=false
    labels:
      - traefik.frontend.rule: Host:registry.docker