Network "barkati" is declared as external, but it is not in the right scope: "local" instead of "swarm"

Hello,

I want to assign static ip to each service with macvlan network named “barkati” but when I deploy my docker-stack yml file using sudo docker stack deploy -c docker-stack9.yml ims i get this error:

network "barkati" is declared as external, but it is not in the right scope: "local" instead of "swarm"

here is my docker stack yml file:

version: "3.8"
services:
    pcscf:
      image: openims/pcscf-v5
      command: bash /opt/OpenIMSCore/pcscf.sh
      deploy:
        mode: replicated
        replicas: 3
      networks:
        default:
          ipv4_address: 192.168.2.11
    scscf:
      image: openims/scscf-v5-5
      command: bash /opt/OpenIMSCore/scscf.sh
      deploy:
        mode: replicated
        replicas: 3
      networks:
        default:
          ipv4_address: 192.168.2.16

networks:
      default:
        external:  
          name: barkati
          external: true

Thank you for your help.

Please share the output of docker network inspect barkati.

It seems like you created the network without the parameter -d overlay.
Note: if you want non-swarm container to be able to use the same network, you also need the parameter --attachable

Note2: last time I checked, swarm services have not been able to use ipv4_address, as this feature was not implemented for swarm services. I expect it to be the next error message, after you re-created your network as overlay network.

This is barkati network inspect:

[
    {
        "Name": "barkati",
        "Id": "v8m1m2heyojuo7nys5c1yjf6d",
        "Created": "2023-02-25T10:53:01.452223759-08:00",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.0.0/16",
                    "Gateway": "192.168.1.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "lb-barkati": {
                "Name": "barkati-endpoint",
                "EndpointID": "009d6a00cd9459045a3b67945a8845cfc1ec329017f6f6758d5bf87e392bb6b0",
                "MacAddress": "02:42:c0:a8:00:81",
                "IPv4Address": "192.168.0.129/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4102",
            "parent": "ens33"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "acafb6397012",
                "IP": "192.168.2.20"
            }
        ]
    }
]

Hmm, it already is an overlay network.

The error message doesn’t really make sense to me, unless one at least one of the nodes a preexisting network with the same name exists that is declared differently.

Update: I can see from the peer list that it’s a single node swarm cluster. So my idea of a preexisting network on one of the other nodes can’t be the issue if there are no other nodes…

I almost missed it, but the network should be defined this way:

networks:
      default:
        external: true
        name: barkati

The old and deprecated or possibly removed way was:

networks:
      default:
        external:  
          name: barkati

But that used to give me a warning with recent compose versions. Let’s assume that the extra external: true was ignored and the old syntax still worked for you. Sometimes I override the default network too, but I have never done it with the overlay network, so if my previous suggestion doesn’t work, you could try to use a different name instead of default.

version: "3.8"
services:
    pcscf:
      image: openims/pcscf-v5
      command: bash /opt/OpenIMSCore/pcscf.sh
      deploy:
        mode: replicated
        replicas: 3
      networks:
        barkati:
          ipv4_address: 192.168.2.11
    scscf:
      image: openims/scscf-v5-5
      command: bash /opt/OpenIMSCore/scscf.sh
      deploy:
        mode: replicated
        replicas: 3
      networks:
        barkati:
          ipv4_address: 192.168.2.16

networks:
     barkati:
        external: true

I just updated the code with the new network name, so it is still using the ipv4_address parameter that @meyay mentioned, but I am curious if it gives you the same error message.

1 Like

Good that you spotted it. I missed it.

Thankyou for your Answer.
with change my network setting on yml file solved my error but as yet, services don’t get static ip as defined on yml file .(for example scscf not get 192.168.2.16)

So it is exactly how @meyay suspected. I can only link one of his answers from another topic in addition to what he mentioned here.

So it looks like you either use docker compose without swarm on a single node or give up on the static IP that we never use anyway.