I can link docker containers with the --link name:alias
parameter, which will create several environment variables within the container, for example ALIAS_PORT_1234_TCP_ADDR
, ALIAS_PORT_1234_TCP_PORT
, ALIAS_PORT_1234_TCP_PROTO
.
The ALIAS_PORT_1234_TCP_ADDR
var can be used to detect the IP of the linked container (even though is is advisable to use the etc/hosts
entry instead, because it will be updated on container restart, while the env vars do not change).
But it is not obvious to my, what I could use these other two variables for. In the given example ALIAS_PORT_1234_TCP_ADDR
will be 1234
and ALIAS_PORT_1234_TCP_PROTO
will be tcp
- but both values are already in the name of the vars.
Could somebody enlighten me, about the intended meaning and use of these variables?
Are there scenarios, in which the exposed port of a linked container is different to what it declares with EXPOSE
? I know that I can bind a container port to the host via -p
but my understanding was, that this has no consequence for linked containers, because they will talk directly to the port of the linked container and need not talk to the host (which would be more difficult because it is not so easy to get the IP of the host inside a container).
Also, why would the protocol of a port change or need to be detected?