Docker links - how to use injected information?

Regarding linking containers I’m baffled about how I’m supposed to use the environment variables inserted into the container. Taking the example given in the docker links page ( Legacy container links | Docker Docs ) it states

$ sudo docker run --rm --name web2 --link db:db training/webapp env
. . .

and then goes on to say

You can see that Docker has created a series of environment variables with useful information about the source db container.

What’s puzzling me is how I’m supposed to use the entry, say “DB_PORT_5432_TCP_PORT=5432” to discover that the DB is listening on port 5432. Given that I need to know the port number 5432 to create the ENV variable name ‘DB_PORT_5432_TCP_PORT’ to discover the value 5432 I don’t see how it’s very useful.

Similarly I’m not certain how I’m supposed to use the DB_NAME entry. Perhaps it’s useful as a key for etcd ?

I’m fully prepared to believe my knowledge is lacking, and that I’m missing something obvious - but I’m genuinely unsure what the developers intended