如何使用docker和traeffik部署项目多个分支

时间:2018-01-29 16:01:48

标签: docker docker-compose branch reverse-proxy traefik

我尝试设置docker / traefik配置,以允许在同一服务器上以不同版本部署我的项目。

问题是我找不到设置traefik的方法,允许根据入口点将网络流量重定向到正确的容器上。

这是我的traefik TOML:

 logLevel = "ERROR"

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[acme]
email = "myemail@mybiz.com"
storage = "acme.json"
entryPoint = "https"
onDemand = true
onHostRule = true
delayDontCheckDNS = 0
acmeLogging = true

[[acme.domains]]
  main = "mydomain.fr"

[docker]
domain = "mydomain.fr"
endpoint = "unix:///var/run/docker.sock"
watch = true

traefik docker-compose file

version: '2'

services:
  proxy:
    image: traefik
    command: --docker --logLevel=DEBUG
    networks:
      - webgateway
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
      # Support SSL
      # - ./config/traefik.toml:/traefik.toml
      # - ./config/acme.json:/acme.json

networks:
  webgateway:
    driver: bridge

我的应用程序docker-compose for DEVELOP branch

version: '2'

services:

  blablabla-develop:
      image: registry.gitlab.com/aaaaaa/bbbbbbb/release:6.6.6
      environment:
          - SPRING_PROFILES_ACTIVE=develop
          - SERVER_URL=http://test.mybiz.fr
          - SERVER_PORT=8090
          - JAVA_OPTS=-Xmx1g
          - SPRING_DATASOURCE_URL=jdbc:postgresql://webapp_blablabla-db-develop_1:5432/xxxxx
          - SPRING_DATASOURCE_USERNAME=xxxxxx
          - SPRING_DATASOURCE_PASSWORD=xxxxxx
      links:
        - blablabla-db-develop
      networks:
          - web
          - back
      restart: always
      labels:
          - "traefik.backend=webapp_blablabla-develop_1"
          - "traefik.frontend.rule=Host:develop.mydomain.fr"
          - "traefik.port=8090"

  blablabla-db-develop:
      image: postgres
      environment:
          - POSTGRES_DB=xxxxx
          - POSTGRES_USER=xxxxx
          - POSTGRES_PASSWORD=xxxxx
      volumes:
          - /home/aaaaa/develop/db/app:/etc/postgresql
          - /home/aaaaa/develop/db/log:/var/log/postgresql
          - /home/aaaaa/develop/db/lib:/var/lib/postgresql
          - /home/aaaaa/develop/db/lib/data:/var/lib/postgresql/data
      restart: always
      networks:
          - back
      labels:
          - "traefik.enable=false"

networks:
  web:
    external:
      name: traefik_webgateway
  back:
    driver: bridge

QA分支的docker-compose文件:

version: '2'

services:

  blablabla-test:
      image: registry.gitlab.com/aaaaaa/bbbbbbb/release:6.6.6
      environment:
          - SPRING_PROFILES_ACTIVE=develop
          - SERVER_URL=http://test.mybiz.fr
          - SERVER_PORT=8090
          - JAVA_OPTS=-Xmx1g
          - SPRING_DATASOURCE_URL=jdbc:postgresql://webapp_blablabla-db-test_1:5432/xxxxx
          - SPRING_DATASOURCE_USERNAME=xxxxxx
          - SPRING_DATASOURCE_PASSWORD=xxxxxx
      links:
        - blablabla-db-test
      networks:
          - web
          - back
      restart: always
      labels:
          - "traefik.backend=webapp_blablabla-test_1"
          - "traefik.frontend.rule=Host:test.mydomain.fr"
          - "traefik.port=8090"

  blablabla-db-test:
      image: postgres
      environment:
          - POSTGRES_DB=xxxxx
          - POSTGRES_USER=xxxxx
          - POSTGRES_PASSWORD=xxxxx
      volumes:
          - /home/aaaaa/test/db/app:/etc/postgresql
          - /home/aaaaa/test/db/log:/var/log/postgresql
          - /home/aaaaa/test/db/lib:/var/lib/postgresql
          - /home/aaaaa/test/db/lib/data:/var/lib/postgresql/data
      restart: always
      networks:
          - back
      labels:
          - "traefik.enable=false"

networks:
  web:
    external:
      name: traefik_webgateway
  back:
    driver: bridge

当我为这两个文件执行docker-compose up -d时,我有一个警告说blablabla-develop_1和blablabla-db-develop_1是孤儿。通过develop.mydomain.fr进行访问并不适用于eigthter。

希望有人可以帮我解决这个docker / traefik设置或至少给我一个有用的链接,traefik doc页面并没有真正帮助我:/

THX

1 个答案:

答案 0 :(得分:0)

在同一个docker-compose文件中添加blablabla-develop,blablabla-db-develop,blablabla-test,blablabla-db-test的设置,其中一个网络用于后端,一个前端网络外部匹配创建到traefik docker中的网络 - 撰写文件。