Correct --add-host documentation regarding host IP address retrieval

Fixes: 10855

The example was actually incorrect for many situations, and also, now
that we have IPv6 we should not that the example is for IPv4 and note
how to find IPv6 addresses.  Also, the device they want to connect to
could be the bridge, or main ethernet device, or some other device
name, so note that as well.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
This commit is contained in:
Phil Estes 2015-02-19 09:40:23 -08:00
parent df7a04f9a6
commit f8a146311d

View file

@ -1962,13 +1962,21 @@ You can add other hosts into a container's `/etc/hosts` file by using one or mor
round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms
```
> **Note:**
> Sometimes you need to connect to the Docker host, which means getting the IP
> address of the host. You can use the following shell commands to simplify this
> process:
>
> $ alias hostip="ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print \$2 }'"
> $ docker run --add-host=docker:$(hostip) --rm -it debian
Sometimes you need to connect to the Docker host from within your
container. To enable this, pass the Docker host's IP address to
the container using the `--add-host` flag. To find the host's address,
use the `ip addr show` command.
The flags you pass to `ip addr show` depend on whether you are
using IPv4 or IPv6 networking in your containers. Use the following
flags for IPv4 address retrieval for a network device named `eth0`:
$ HOSTIP=`ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1`
$ docker run --add-host=docker:${HOSTIP} --rm -it debian
For IPv6 use the `-6` flag instead of the `-4` flag. For other network
devices, replace `eth0` with the correct device name (for example `docker0`
for the bridge device).
## save