My mental model is wrong so I'm probably about to say something stupid.
I'm not familiar with the way docker works so bear with me...


On 08/23/2016 03:01 AM, Christian Kniep wrote:
> 
> ###
> $ docker service create --name nginx --mode=global -e 
> SERVICE_HOSTNAME=$(hostname -f)  nginx
> ###

This looks like it would set the SERVICE_HOSTNAME environment variable
inside the container to the hostname that you're running the command on.


> Each of the tasks (a container to-be-run on one of the nodes) will
> now find an environment variable SERVICE_HOSTNAME, but it will a) be
> the same among all containers and b) it will show the hostname from
> which the service was created.
> 

Cool, I'm not confused yet.


> On docker host with non-gentoo I can just run this (e.g. on my DockerForMac):
> 
> $ docker service create --mount 
> type=bind,source=/etc/hostname,target=/etc/docker-hostname:ro --name nginx  
> nginx

Doesn't this mount the /etc/hostname file, from the host that you run
the command on, to the /etc/docker-hostname file within the container?
If so, it would have the same problem as the environment variable, so
it's got to be doing something else.

...Is it the other way around? Does it mount /etc/hostname from the
container somewhere on the outside?


> By doing so I am able to determine on which host I am running on
> each tasks without much hassle.
> 
> $ docker exec -ti 56e8b2eaecc3 cat /etc/docker-hostname
> 

If this runs *inside* the container, then instead of using "cat" on a
file, why not just run "hostname"? That should give you the hostname of
the machine it ran on. For example,

  docker exec -ti 56e8b2eaecc3 hostname

But, if that runs outside the container, then... I need a better
understanding of what's going on before I start throwing out ideas.


Reply via email to