From 31200920d70cc43759247a647576c926ed46e9c1 Mon Sep 17 00:00:00 2001 From: Usha Mandya Date: Fri, 31 Jul 2020 14:51:17 +0100 Subject: [PATCH] Add a networking example --- docker-for-mac/networking.md | 27 +++++++++++++++++++++------ docker-for-windows/networking.md | 27 +++++++++++++++++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/docker-for-mac/networking.md b/docker-for-mac/networking.md index ed391b08da..c8bbbf0829 100644 --- a/docker-for-mac/networking.md +++ b/docker-for-mac/networking.md @@ -68,13 +68,28 @@ There are two scenarios that the above limitations affect: #### I want to connect from a container to a service on the host -The host has a changing IP address (or none if you have no network access). From -18.03 onwards our recommendation is to connect to the special DNS name -`host.docker.internal`, which resolves to the internal IP address used by the -host. -This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac. +The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name +`host.docker.internal` which resolves to the internal IP address used by the +host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac. -The gateway is also reachable as `gateway.docker.internal`. +You can also reach the gateway using `gateway.docker.internal`. + +If you have installed Python on your machine, use the following instructions as an example to connect from a container to a service on the host: + +1. Run the following command to start a simple HTTP server on port 8000. + + `python -m http.server 8000` + + If you have installed Python 2.x, run `python -m SimpleHTTPServer 8000`. + +2. Now, run a container, install `curl`, and try to connect to the host using the following commands: + + ```console + $ docker run --rm -it alpine sh + # apk add curl + # curl http://host.docker.internal:8000 + # exit + ``` #### I want to connect to a container from the Mac diff --git a/docker-for-windows/networking.md b/docker-for-windows/networking.md index 3e5a19744b..cea1a2793b 100644 --- a/docker-for-windows/networking.md +++ b/docker-for-windows/networking.md @@ -68,13 +68,28 @@ There are two scenarios that the above limitations affect: #### I want to connect from a container to a service on the host -The host has a changing IP address (or none if you have no network access). From -18.03 onwards our recommendation is to connect to the special DNS name -`host.docker.internal`, which resolves to the internal IP address used by the -host. -This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows. +The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name +`host.docker.internal` which resolves to the internal IP address used by the +host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows. -The gateway is also reachable as `gateway.docker.internal`. +You can also reach the gateway using `gateway.docker.internal`. + +If you have installed Python on your machine, use the following instructions as an example to connect from a container to a service on the host: + +1. Run the following command to start a simple HTTP server on port 8000. + + `python -m http.server 8000` + + If you have installed Python 2.x, run `python -m SimpleHTTPServer 8000`. + +2. Now, run a container, install `curl`, and try to connect to the host using the following commands: + + ```console + $ docker run --rm -it alpine sh + # apk add curl + # curl http://host.docker.internal:8000 + # exit + ``` #### I want to connect to a container from Windows