Docker Community Forums

Share and learn in the Docker community.

Access node labels from container running with in swarm


(Craigham) #1

I have a few nodes within a swarm which have usb attached devices.

I can set up a label to constrain deployment of the image to only these nodes no problem.

However, within the container I need a way to find out which USB port has the device attached. I was thinking I could add a label which defines that data to the node. But, can I read node labels from within my containers?

I would also like to specify a different physical location label for use within each if the containers. Any idea how I can specify different values for the different instances of the container running within the swarm?

thanks,
craig


(Cycmoto) #2

Hi @craigham any luck with the question? I would love to learn how to go about it if you have solve it!


(Craigham) #3

sadly I haven’t had any responses.


(Sreenivas Makam) #4

Hi
I see that there are 2 questions here:
To read labels from within container, “/var/run/docker.sock” can be mounted inside container and docker socket endpoint can be used to access label.
To have container label, we can use “docker service create --container-label”. But this would have same labels inside all containers. There is both service level label and container level label. I am not sure if its a good idea to have different labels for containers running in a single service. I dont think we can do this currently.

Regards
Sreenivas .