dockercloud haproxy在不同的端口上有多个服务

是否有可能configurationdockercloud / haproxy与多个后端服务,但在不同的端口上侦听? 我试图得到一个docker-composeconfiguration工作与端口80上的nginx为Web前端,然后在8080运行Spring Boot应用程序的容器。

默认情况下,haproxy显示web和addressbook的链接容器(参见下面的.yml文件),但是默认情况下,它们都是通过happroxy在端口80上公开的,所以Spring Boot容器从不接收8080上的stream量。

这是可能的configuration,还是我需要运行2个不同的haproxy容器,一个用于web,另一个用于REST后端服务?

这是我的docker-compose.yml到目前为止:

version: '2' #build: # context: ./haproxy # image: haproxy # dockerfile: Dockerfile services: mongodata: image: mongo:3.2 volumes: - /data/db entrypoint: /bin/bash mongo: image: mongo:3.2 depends_on: - mongodata volumes_from: - mongodata ports: #only specify internal port, not external, so we can scale with docker-compose scale - "27017" addressbook: image: addressbook depends_on: - mongo environment: - MONGODB_DB_NAME=addressbook ports: - "8080" links: - mongo web: image: docker-web-angularjs ports: - "80" lb: image: dockercloud/haproxy #TODO: need to add an haproxy.cfg to configure for addressbook instances exposed behind 8080? #or can be configured via container properties? #image: haproxy depends_on: - addressbook environment: - STATS_PORT=1936 - STATS_AUTH="admin:password" links: - addressbook - web volumes: - /var/run/docker.sock:/var/run/docker.sock ports: - 80:80 - 8080:8080 - 1936:1936 

您可以使用两个不同的path公开两个服务,这两个path都位于haproxy容器的同一个端口上。 您可以使用环境variablesVIRTUAL_HOST来完成addressbookweb容器的操作:

 addressbook: image: addressbook depends_on: - mongo environment: - MONGODB_DB_NAME=addressbook - VIRTUALHOST="/addressbook/*" ports: - "8080" links: - mongo web: image: docker-web-angularjs environment: - VIRTUALHOST="/web/*" ports: - "80" 

不幸的是,haproxy默认不会删除webaddressbookpath,所以您需要更新这两个应用程序才能pipe理“基本path”。

对我来说,使用Traefik来实现这个目标更容易。

 addressbook: image: addressbook depends_on: - mongo environment: - MONGODB_DB_NAME=addressbook labels: - "traefik.backend=spring_boot" - "traefik.protocol=http" - "traefik.port=8080" - "traefik.frontend.entryPoints=http_8080" ports: - "8080" links: - mongo web: image: docker-web-angularjs labels: - "traefik.backend=nginx" - "traefik.protocol=http" - "traefik.port=80" - "traefik.frontend.entryPoints=http_80" ports: - "80" lb: image: traefik command: "--web --web.address=8081 --docker --docker.domain=docker.localhost \ --logLevel=DEBUG \ --entryPoints='Name:http_80 Address::80' \ --entryPoints='Name:http_8080 Address::8080'" ports: - 80:80 - 8080:8080 - 8081:8081 volumes: - /var/run/docker.sock:/var/run/docker.sock - /dev/null:/traefik.toml