Reputation: 453
I run a docker swarm with docker swarm mode. Let's say I have 4 nodes, 1 manager, 3 worker. The hostnames are:
I start the service in global
mode, so every node runs the service once.
Let's say the command looks like this:
docker service create --name myservice --mode global --network mynetwork ubuntu wait 3600
mynetwork
is an overlay network.
Now I am trying to access the hostname of the docker host in the containers, so I can pass the hostname to an application in the container.
I tried to pass the hostname with the environment variables (--env hostname=$(hostname)
), but actually ${hostname}
is only executed on the manager and the hostname is set to manager0
for all nodes.
Is there a way to access the hostname or pass the hostname to the containers?
Upvotes: 6
Views: 16820
Reputation: 1378
Here is the feature request, that has been implemented in docker version 17.10
https://github.com/moby/moby/issues/30966
Upvotes: 1