Search code examples
dockerdocker-composedocker-swarm

Connect to a service on a different stack from docker-compose


I'm trying to connect a service one in stack abc - abc_one to service two in stack zyx - zyx_two . These services share the network az-network .

I've read here that it's possible manually , but I need to do this with docker-compose.yml files for deploying to my swarm .

 

A simple version of of abc_one is

version:  "3.5"

services:

    one:
        image: "10.30.13.81:5000/dotnetmicroservice"
        environment:
            ElasticSearchLogging:Uri: "http://zyx_two:9200/"
        networks:
            - az-network

networks:
    az-network:
        external: true

and zyx_two

version:  "3.5"

services:

    two:
        image: "10.30.13.81:5000/dotnetmicroservice"
        networks:
            - az-network

networks:
    az-network:
        external: true

Solution

  • It should work without adding zyx_ prefix.

    az-network must be an overlay docker network

    docker network create -d overlay --attachable az-network
    

    Service name must be unique on all stacks in the same network.

    abc stack (docker stack deploy -c abc-compose.yml abc)

    version:  "3.5"
    
    services:
    
        one:
            image: "10.30.13.81:5000/dotnetmicroservice"
            environment:
                ElasticSearchLogging:Uri: "http://two:9200/"
            networks:
                - az-network
    
    networks:
        az-network:
            external: true
    

    zyx stack (docker stack deploy -c zyx-compose.yml zyx)

    version:  "3.5"
    
    services:
    
    two:
        image: "10.30.13.81:5000/dotnetmicroservice"
        networks:
            - az-network
    
    networks:
        az-network:
            external: true