Search code examples
dockerdocker-swarmdocker-stack

Network undefined issue in docker stack


I am using docker stack to deploy some services on a swarm network with two nodes . I created overlay network which I can see through docker network ls but when I am trying to use that network in docker stack file I am continuously getting error Network undefined . Here is my docker stack file

version: '3.4'

services:
    orderer1st:
        image: hyperledger/fabric-orderer:1.2.1
        networks:
            - fabricoverlay
        ports:
              - 7050:7050

        environment:
              - ORDERER_GENERAL_LOGLEVEL=info
              - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
              - ORDERER_GENERAL_GENESISMETHOD=file
              - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
              - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
              - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp

        command: orderer
        volumes:
             - ./channel-configuration/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block
             - ./msp:/var/hyperledger/orderer/msp

Am I doing something wrong here? I dont know why docker stack is been unable to pick overlay network

Docker Version:

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:56 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:21 2018
  OS/Arch:          linux/amd64
  Experimental:     false

Solution

  • You have to add the networks as root objects in the compose file so the service knows how to find it.

    networks:
        fabricoverlay:
            external: true
    

    Note that an easier option might be letting swarm create that network for your stack. Just remove the network references in the compose file, delete the manually created network, and deploy the stack. Docker will create it for you, one network per stack.