Browse code

Merge pull request #9227 from SvenDowideit/add-client-ip-to-hosts

Add an example of how to add your client IP to the container hosts file

Fred Lifton authored on 2014/11/29 10:44:11
Showing 1 changed files
... ...
@@ -1610,6 +1610,30 @@ container exits with a non-zero exit status more than 10 times in a row
1610 1610
 Docker will abort trying to restart the container.  Providing a maximum
1611 1611
 restart limit is only valid for the ** on-failure ** policy.
1612 1612
 
1613
+### Adding entries to a container hosts file
1614
+
1615
+You can add other hosts into a container's `/etc/hosts` file by using one or more
1616
+`--add-host` flags. This example adds a static address for a host named `docker`:
1617
+
1618
+```
1619
+    $ docker run --add-host=docker:10.180.0.1 --rm -it debian
1620
+    $$ ping docker
1621
+    PING docker (10.180.0.1): 48 data bytes
1622
+    56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms
1623
+    56 bytes from 10.180.0.1: icmp_seq=1 ttl=254 time=30.705 ms
1624
+    ^C--- docker ping statistics ---
1625
+    2 packets transmitted, 2 packets received, 0% packet loss
1626
+    round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms
1627
+```
1628
+
1629
+> **Note:**
1630
+> Sometimes you need to connect to the Docker host, which means getting the IP
1631
+> address of the host. You can use the following shell commands to simplify this
1632
+> process:
1633
+>
1634
+>      $ alias hostip="ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print \$2 }'"
1635
+>      $ docker run  --add-host=docker:$(hostip) --rm -it debian
1636
+
1613 1637
 ## save
1614 1638
 
1615 1639
     Usage: docker save [OPTIONS] IMAGE [IMAGE...]