Home Explore Blog CI



docker

3rd chunk of `content/manuals/engine/cli/proxy.md`
052118026250e78f221acbaaa6b293b7e7b90027580af9f40000000100000d13
shown in the [earlier section](#configure-the-docker-client), environment
variables for containers that you run are set as follows:

```console
$ docker run --rm alpine sh -c 'env | grep -i  _PROXY'
https_proxy=http://proxy.example.com:3129
HTTPS_PROXY=http://proxy.example.com:3129
http_proxy=http://proxy.example.com:3128
HTTP_PROXY=http://proxy.example.com:3128
no_proxy=*.test.example.com,.example.org,127.0.0.0/8
NO_PROXY=*.test.example.com,.example.org,127.0.0.0/8
```

### Build with a proxy configuration

When you invoke a build, proxy-related build arguments are pre-populated
automatically, based on the proxy settings in your Docker client configuration
file.

Assuming a proxy configuration like the example shown in the
[earlier section](#configure-the-docker-client), environment
are set as follows during builds:

```console
$ docker build \
  --no-cache \
  --progress=plain \
  - <<EOF
FROM alpine
RUN env | grep -i _PROXY
EOF
```

```console
#5 [2/2] RUN env | grep -i _PROXY
#5 0.100 HTTPS_PROXY=https://proxy.example.com:3129
#5 0.100 no_proxy=*.test.example.com,.example.org,127.0.0.0/8
#5 0.100 NO_PROXY=*.test.example.com,.example.org,127.0.0.0/8
#5 0.100 https_proxy=https://proxy.example.com:3129
#5 0.100 http_proxy=http://proxy.example.com:3128
#5 0.100 HTTP_PROXY=http://proxy.example.com:3128
#5 DONE 0.1s
```

### Configure proxy settings per daemon

The `default` key under `proxies` in `~/.docker/config.json` configures the proxy
settings for all daemons that the client connects to.
To configure the proxies for individual daemons,
use the address of the daemon instead of the `default` key.

The following example configures both a default proxy config,
and a no-proxy override for the Docker daemon on address
`tcp://docker-daemon1.example.com`:

```json
{
 "proxies": {
   "default": {
     "httpProxy": "http://proxy.example.com:3128",
     "httpsProxy": "https://proxy.example.com:3129",
     "noProxy": "*.test.example.com,.example.org,127.0.0.0/8"
   },
   "tcp://docker-daemon1.example.com": {
     "noProxy": "*.internal.example.net"
   }
 }
}
```

## Set proxy using the CLI

Instead of [configuring the Docker client](#configure-the-docker-client),
you can specify proxy configurations on the command-line when you invoke the
`docker build` and `docker run` commands.

Proxy configuration on the command-line uses the `--build-arg` flag for builds,
and the `--env` flag for when you want to run containers with a proxy.

```console
$ docker build --build-arg HTTP_PROXY="http://proxy.example.com:3128" .
$ docker run --env HTTP_PROXY="http://proxy.example.com:3128" redis
```

For a list of all the proxy-related build arguments that you can use with the
`docker build` command, see
[Predefined ARGs](/reference/dockerfile.md#predefined-args).
These proxy values are only available in the build container.
They're not included in the build output.

## Proxy as environment variable for builds

Don't use the `ENV` Dockerfile instruction to specify proxy settings for builds.
Use build arguments instead.

Using environment variables for proxies embeds the configuration into the image.
If the proxy is an internal proxy, it might not be accessible for containers
created from that image.

Embedding proxy settings in images also poses a security risk, as the values
may include sensitive information.

Title: Proxy Configuration: Per-Daemon, CLI, and Environment Variables
Summary
This section discusses configuring proxy settings for Docker daemons, including setting a default configuration and overriding it for specific daemons. It also covers specifying proxy configurations using the command-line interface (CLI) with the `docker build` and `docker run` commands. Finally, it advises against using the `ENV` instruction in Dockerfiles for proxy settings, recommending build arguments instead to avoid embedding proxy configurations into the image.