Is there any way to know the service name (swarm) from a container?

837 views Asked by At

Let's say that I have launch a service in Swarm like this :

docker service create --replicas 1 --name helloworld busybox bash

Is there any way to know that the container that will be run is controlled by a service called "helloworld"?

1

There are 1 answers

0
VPusher On

You can't. Containers do not know about the current architecture they are being run into. And that is well.

If you tell a container how is designed its hosting architecture, and then rely on it from within the container, you instantly lose all the modularity and scalability of using Swarm.

Nevertheless, you might need to configure some stuff for your container. I would advise to use environment variables and pass through the information you need.

docker service create --replicas 1 --name helloworld -e SERVICE=helloworld busybox bash