Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I filter docker swarm nodes by label?

I'm running docker 1.12.1 and can't get node filtering by label to work. I first add the "test" label:

$ docker node update --label-add test mr-host
mr-host

When I attempt to filter by it, no nodes are shown:

$ docker node ls --filter label=test
ID  HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS

Filtering by other criteria such as name works fine:

$ docker node ls --filter name=mr-host
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
1c48m4msidbqwx7vj0lwib8ef *  mr-host   Ready   Active        Leader

The label is shown when I inspect the node:

$ docker node inspect mr-host
[
    {
        "ID": "1c48m4msidbqwx7vj0lwib8ef",
        "Version": {
            "Index": 4865874
        },
        "CreatedAt": "2016-10-12T15:20:10.463286132Z",
        "UpdatedAt": "2016-10-13T16:29:03.113522485Z",
        "Spec": {
            "Labels": {
                "test": ""
            },
            "Role": "manager",
            "Availability": "active"
        },
        "Description": {
            "Hostname": "mr-host",
            "Platform": {
                "Architecture": "x86_64",
                "OS": "linux"
            },
            "Resources": {
                "NanoCPUs": 10000000000,
                "MemoryBytes": 67548012544
            },
            "Engine": {
                "EngineVersion": "1.12.1",
                "Plugins": [
                    {
                        "Type": "Network",
                        "Name": "bridge"
                    },
                    {
                        "Type": "Network",
                        "Name": "host"
                    },
                    {
                        "Type": "Network",
                        "Name": "null"
                    },
                    {
                        "Type": "Network",
                        "Name": "overlay"
                    },
                    {
                        "Type": "Volume",
                        "Name": "local"
                    }
                ]
            }
        },
        "Status": {
            "State": "ready"
        },
        "ManagerStatus": {
            "Leader": true,
            "Reachability": "reachable",
            "Addr": "192.168.0.118:2377"
        }
    }
]

What am I doing wrong? I'm pretty sure I've followed the documentation here correctly: https://docs.docker.com/engine/reference/commandline/node_ls/#/id

like image 234
Ashley Reid Avatar asked Oct 13 '16 16:10

Ashley Reid


3 Answers

Simple answer: this doesn't work like you'd think it would, but it looks like they might fix it.

Quoting from the Github issue:

The confusion comes from the fact that we have two set of labels:

Node labels (the ones you've been setting through docker node update) Engine labels (the ones that you set when you start docker daemon with --label) Label filtering in docker node ls is looking at engine labels rather than node labels.

We should probably revert to node label filtering rather than engine filtering

like image 74
Ashley Reid Avatar answered Oct 19 '22 10:10

Ashley Reid


As I believe you've seen (based on the thumbs up it received), this is a known issue (#27231) with docker swarm.

like image 39
BMitch Avatar answered Oct 19 '22 10:10

BMitch


This issue was finally fixed : #27231#issuecomment-767696365

Now, you have to prefix the filter with "node" :

docker node ls --filter node.label=test
like image 36
chok Avatar answered Oct 19 '22 10:10

chok