1 |
My mental model is wrong so I'm probably about to say something stupid. |
2 |
I'm not familiar with the way docker works so bear with me... |
3 |
|
4 |
|
5 |
On 08/23/2016 03:01 AM, Christian Kniep wrote: |
6 |
> |
7 |
> ### |
8 |
> $ docker service create --name nginx --mode=global -e SERVICE_HOSTNAME=$(hostname -f) nginx |
9 |
> ### |
10 |
|
11 |
This looks like it would set the SERVICE_HOSTNAME environment variable |
12 |
inside the container to the hostname that you're running the command on. |
13 |
|
14 |
|
15 |
> Each of the tasks (a container to-be-run on one of the nodes) will |
16 |
> now find an environment variable SERVICE_HOSTNAME, but it will a) be |
17 |
> the same among all containers and b) it will show the hostname from |
18 |
> which the service was created. |
19 |
> |
20 |
|
21 |
Cool, I'm not confused yet. |
22 |
|
23 |
|
24 |
> On docker host with non-gentoo I can just run this (e.g. on my DockerForMac): |
25 |
> |
26 |
> $ docker service create --mount type=bind,source=/etc/hostname,target=/etc/docker-hostname:ro --name nginx nginx |
27 |
|
28 |
Doesn't this mount the /etc/hostname file, from the host that you run |
29 |
the command on, to the /etc/docker-hostname file within the container? |
30 |
If so, it would have the same problem as the environment variable, so |
31 |
it's got to be doing something else. |
32 |
|
33 |
...Is it the other way around? Does it mount /etc/hostname from the |
34 |
container somewhere on the outside? |
35 |
|
36 |
|
37 |
> By doing so I am able to determine on which host I am running on |
38 |
> each tasks without much hassle. |
39 |
> |
40 |
> $ docker exec -ti 56e8b2eaecc3 cat /etc/docker-hostname |
41 |
> |
42 |
|
43 |
If this runs *inside* the container, then instead of using "cat" on a |
44 |
file, why not just run "hostname"? That should give you the hostname of |
45 |
the machine it ran on. For example, |
46 |
|
47 |
docker exec -ti 56e8b2eaecc3 hostname |
48 |
|
49 |
But, if that runs outside the container, then... I need a better |
50 |
understanding of what's going on before I start throwing out ideas. |