dockernetwork-programmingdocker-swarmdocker-swarm-mode

Docker swarm overlay, single node, no connection between services


I'm trying to make a connection from one service to another, to achieve it I created an overlay network and two services attached to it like so.

$ docker network create -d overlay net1
$ docker service create --name busybox --network net1 busybox sleep 3000
$ docker service create --name busybox2 --network net1 busybox sleep 3000

Now I make sure my services are running and both connected to overlay.

$ docker ps
CONTAINER ID   IMAGE            COMMAND        CREATED              STATUS              PORTS     NAMES
ecc8dd465cb1   busybox:latest   "sleep 3000"   About a minute ago   Up About a minute             busybox2.1.uw597s90tkvbcaisgaq7los2q
f8cfe793e3d9   busybox:latest   "sleep 3000"   About a minute ago   Up About a minute             busybox.1.l5lxp4v0mcbujqh79dne2ds42

$ docker network inspect net1
[
    {
        "Name": "net1",
        "Id": "5dksx8hlxh1rbj42pva21obyz",
        "Created": "2021-06-22T14:23:43.739770415Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.4.0/24",
                    "Gateway": "10.0.4.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ecc8dd465cb12c622f48b109529534279dddd4fe015a66c848395157fb73bc69": {
                "Name": "busybox2.1.uw597s90tkvbcaisgaq7los2q",
                "EndpointID": "b666f6374a815341cb8af7642a7523c9bb153f153b688218ad006605edd6e196",
                "MacAddress": "02:42:0a:00:04:06",
                "IPv4Address": "10.0.4.6/24",
                "IPv6Address": ""
            },
            "f8cfe793e3d97f72393f556c2ae555217e32e35b00306e765489ac33455782aa": {
                "Name": "busybox.1.l5lxp4v0mcbujqh79dne2ds42",
                "EndpointID": "fff680bd13a235c4bb050ecd8318971612b66954f7bd79ac3ee0799ee18f16bf",
                "MacAddress": "02:42:0a:00:04:03",
                "IPv4Address": "10.0.4.3/24",
                "IPv6Address": ""
            },
            "lb-net1": {
                "Name": "net1-endpoint",
                "EndpointID": "2a3b02f66f395e613c6bc88f16d0723762d28488b429a9e50f7df24c04e9f1f0",
                "MacAddress": "02:42:0a:00:04:04",
                "IPv4Address": "10.0.4.4/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4101"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "e1c2ac76b95b",
                "IP": "10.18.0.6"
            }
        ]
    }
]

So far so good! Next I ssh into one of containers and try to nslookup the second one, but have no luck.

$ docker exec -it busybox.1.l5lxp4v0mcbujqh79dne2ds42 sh
/ # nslookup busybox2
Server:     127.0.0.11
Address:    127.0.0.11:53

Non-authoritative answer:
*** Can't find busybox2: No answer

*** Can't find busybox2: No answer

/ # nslookup busybox2.1.uw597s90tkvbcaisgaq7los2q
Server:     127.0.0.11
Address:    127.0.0.11:53

Non-authoritative answer:
*** Can't find busybox2.1.uw597s90tkvbcaisgaq7los2q: No answer

*** Can't find busybox2.1.uw597s90tkvbcaisgaq7los2q: No answer

I know that overlay questions are quite common here, but they are mostly about node to node connections, not single node swarm. Another think to keep in mind is there is no local firewall on that node at all.

Am I trying to connect in the wrong way or is it a configuration issue?


Solution

  • The solution was simply adding a --attachable flag to network create command. After that I could ping my services by name.

    Turns out you need that flag no matter if you are adding stack (in my case I have multiple stacks in the same swarm) or single services.