diff --git a/engine/userguide/networking/index.md b/engine/userguide/networking/index.md index e0e4b51e9f..dd56dd912a 100644 --- a/engine/userguide/networking/index.md +++ b/engine/userguide/networking/index.md @@ -541,6 +541,63 @@ network and user-defined bridge networks. b9788c7adca3 nginx "nginx -g 'daemon ..." 43 hours ago Up 3 seconds 80/tcp, 443/tcp, 0.0.0.0:8080->80/tcp goofy_brahmagupta ``` +## Use a proxy server with containers + +If your container needs to use an HTTP, HTTPS, or FTP proxy server, you can +configure it in different ways: + +- In Docker 17.07 and higher, you can configure the Docker client to pass + proxy information to containers automatically. + +- In Docker 17.06 and lower, you must set appropriate environment variables + within the container. You can do this when you build the image (which makes + the image less portable) or when you create or run the container. + +### Configure the Docker Client + +{% include edge_only.md section="option" %} + +1. On the Docker client, create or edit the file `~/.config.json` in the + home directory of the user which starts containers. Add JSON such as the + following, substituting the type of proxy with `httpsproxy` or `ftpproxy` if + necessary, and substituting the address and port of the proxy server. You + can configure multiple proxy servers at the same time. + + You can optionally exclude hosts or ranges from going through the proxy + server by setting a `noProxy` key to one or more comma-separated IP + addresses or hosts. Using the `*` character as a wildcard is supported, as + shown in this example. + + ```json + { + "proxies": + { + "httpProxy": "http://127.0.0.1:3001", + "noProxy": "*.test.example.com,.example2.com" + } + } + ``` + + Save the file. + +2. When you create or start new containers, the environment variables will be + set automatically within the container. + +### Set the environment variables manually + +When you build the image, or using the `--env` flag when you create or run the +container, you can set one or more of the following variables to the appropriate +value. This method makes the image less portable, so if you have Docker 17.07 +or higher, you should [configure the Docker client](#configure-the-docker-client) +instead. + +| Variable | Dockerfile example | `docker run` Example | +|:--------------|:-------------------------------------------------|:----------------------------------------------------| +| `HTTP_PROXY` | `ENV HTTP_PROXY "http://127.0.0.1:3001"` | `--env HTTP_PROXY "http://127.0.0.1:3001"` | +| `HTTPS_PROXY` | `ENV HTTPS_PROXY "https://127.0.0.1:3001"` | `--env HTTPS_PROXY "https://127.0.0.1:3001"` | +| `FTP_PROXY` | `ENV FTP_PROXY "ftp://127.0.0.1:3001"` | `--env FTP_PROXY "ftp://127.0.0.1:3001"` | +| `NO_PROXY` | `ENV NO_PROXY "*.test.example.com,.example2.com" | `--env NO_PROXY "*.test.example.com,.example2.com"` | + ## Links Before Docker included user-defined networks, you could use the Docker `--link`