如何使用同一映像创建多个Docker Swarm服务?

时间:2020-07-29 15:24:28

标签: docker docker-compose docker-swarm docker-swarm-mode

我是Docker Swarm的新手,我需要创建不同的Docker Swarm堆栈,该堆栈可通过不同的URL进行访问,以使用不同的环境(如dev,qa)使用同一映像。

Ex - service1 - http://service1
     service2 - http://service2

docker-compose-dev.yaml

services:
  service1:
    image: image
    deploy:
      replicas: 1
      labels:
        com.docker.lb.hosts: demo-dev.example.com
        com.docker.lb.port: 8181
        com.docker.lb.network: demo_service1-network
        com.docker.ucp.access.label: '/development'
    networks:
      - service1-network

networks:
  service1-network:
    driver: overlay

docker-compose-qa.yaml

services:
  service2:
    image: image
    deploy:
      replicas: 1
      labels:
        com.docker.lb.hosts: demo-qa.example.com
        com.docker.lb.port: 8181
        com.docker.lb.network: demo_service2-network
        com.docker.ucp.access.label: '/development'
    networks:
      - service2-network

networks:
  service2-network:
    driver: overlay

0 个答案:

没有答案