一个主机用于多个容器和基于路径的交换容器

时间:2017-08-17 12:25:09

标签: docker traefik

我将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,第二个是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容器。我应该改变什么?

1 个答案:

答案 0 :(得分:1)

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

试试这个:

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