Merge pull request #19846 from dvdksn/fix-conflicting-http-proxy-daemon

fix: conflicting http proxy configuration for daemon
This commit is contained in:
David Karlsson 2024-06-24 09:11:35 +02:00 committed by GitHub
commit 5871e24952
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 64 additions and 50 deletions

View File

@ -233,7 +233,9 @@ for real-time tasks per runtime period. For instance, with the default period of
containers using the real-time scheduler can run for 950000 microseconds for every containers using the real-time scheduler can run for 950000 microseconds for every
1000000-microsecond period, leaving at least 50000 microseconds available for 1000000-microsecond period, leaving at least 50000 microseconds available for
non-real-time tasks. To make this configuration permanent on systems which use non-real-time tasks. To make this configuration permanent on systems which use
`systemd`, see [Control and configure Docker with systemd](../daemon/systemd.md). `systemd`, create a systemd unit file for the `docker` service. For an example,
see the instruction on how to configure the daemon to use a proxy with a
[systemd unit file](../daemon/proxy.md#systemd-unit-file).
#### Configure individual containers #### Configure individual containers

View File

@ -127,4 +127,4 @@ documentation. Some places to go next include:
- [Limit a container's resources](../containers/resource_constraints.md) - [Limit a container's resources](../containers/resource_constraints.md)
- [Configure storage drivers](../../storage/storagedriver/select-storage-driver.md) - [Configure storage drivers](../../storage/storagedriver/select-storage-driver.md)
- [Container security](../../engine/security/_index.md) - [Container security](../../engine/security/_index.md)
- [Configure the Docker daemon to use a proxy](./systemd.md#httphttps-proxy) - [Configure the Docker daemon to use a proxy](./proxy.md)

View File

@ -1,44 +1,38 @@
--- ---
description: Learn about controlling and configuring the Docker daemon using systemd description: Learn how to configure the Docker daemon to use an HTTP proxy
keywords: dockerd, daemon, systemd, configuration, proxy, networking keywords: dockerd, daemon, configuration, proxy, networking, http_proxy, https_proxy, no_proxy, systemd, environment variables
title: Configure the daemon with systemd title: Configure the daemon to use a proxy
aliases: aliases:
- /articles/host_integration/ - /articles/host_integration/
- /articles/systemd/ - /articles/systemd/
- /engine/admin/systemd/ - /engine/admin/systemd/
- /engine/articles/systemd/ - /engine/articles/systemd/
- /config/daemon/systemd/
--- ---
This page describes how to customize daemon settings when using systemd. <a name="httphttps-proxy"><!-- included for deep-links to old section --></a>
## Custom Docker daemon options If your organization uses a proxy server to connect to the internet, you may
need to configure the Docker daemon to use the proxy server. The daemon uses
a proxy server to access images stored on Docker Hub and other registries,
and to reach other nodes in a Docker swarm.
Most configuration options for the Docker daemon are set using the `daemon.json` This page describes how to configure a proxy for the Docker daemon. For
configuration file. See [Docker daemon configuration overview](./index.md) for instructions on configuring proxy settings for the Docker CLI, see [Configure
more information. Docker to use a proxy server](../../network/proxy.md).
## Manually create the systemd unit files There are two ways you can configure these settings:
When installing the binary without a package manager, you may want to integrate - [Configuring the daemon](#daemon-configuration) through a configuration file or CLI flags
Docker with systemd. For this, install the two unit files (`service` and - Setting [environment variables](#environment-variables) on the system
`socket`) from
[the GitHub repository](https://github.com/moby/moby/tree/master/contrib/init/systemd)
to `/etc/systemd/system`.
### Configure the Docker daemon to use a proxy server {#httphttps-proxy} Configuring the daemon directly takes precedence over environment variables.
The Docker daemon uses the following environment variables in ## Daemon configuration
its start-up environment to configure HTTP or HTTPS proxy behavior:
- `HTTP_PROXY` You may configure proxy behavior for the daemon in the `daemon.json` file,
- `http_proxy` or using CLI flags for the `--http-proxy` or `--https-proxy` flags for the
- `HTTPS_PROXY` `dockerd` command. Configuration using `daemon.json` is recommended.
- `https_proxy`
- `NO_PROXY`
- `no_proxy`
In Docker Engine version 23.0 and later versions, you may also configure proxy
behavior for the daemon in the [`daemon.json` file](./index.md#configure-the-docker-daemon):
```json ```json
{ {
@ -50,11 +44,28 @@ behavior for the daemon in the [`daemon.json` file](./index.md#configure-the-doc
} }
``` ```
These configurations override the default `docker.service` systemd file. After changing the configuration file, restart the daemon for the proxy configuration to take effect:
If you're behind an HTTP or HTTPS proxy server, for example in corporate ```console
settings, the daemon proxy configurations must be specified in the systemd $ sudo systemctl restart docker
service file, not in the `daemon.json` file or using environment variables. ```
## Environment variables
The Docker daemon checks the following environment variables in its start-up
environment to configure HTTP or HTTPS proxy behavior:
- `HTTP_PROXY`
- `http_proxy`
- `HTTPS_PROXY`
- `https_proxy`
- `NO_PROXY`
- `no_proxy`
### systemd unit file
If you're running the Docker daemon as a systemd service, you can create a
systemd drop-in file that sets the variables for the `docker` service.
> **Note for rootless mode** > **Note for rootless mode**
> >
@ -62,12 +73,12 @@ service file, not in the `daemon.json` file or using environment variables.
> in [rootless mode](../../engine/security/rootless.md). When running in > in [rootless mode](../../engine/security/rootless.md). When running in
> rootless mode, Docker is started as a user-mode systemd service, and uses > rootless mode, Docker is started as a user-mode systemd service, and uses
> files stored in each users' home directory in > files stored in each users' home directory in
> `~/.config/systemd/user/docker.service.d/`. In addition, `systemctl` must be > `~/.config/systemd/<user>/docker.service.d/`. In addition, `systemctl` must
> executed without `sudo` and with the `--user` flag. Select the _"rootless > be executed without `sudo` and with the `--user` flag. Select the "Rootless
> mode"_ tab below if you are running Docker in rootless mode. > mode" tab if you are running Docker in rootless mode.
{{< tabs >}} {{< tabs >}}
{{< tab name="regular install" >}} {{< tab name="Regular install" >}}
1. Create a systemd drop-in directory for the `docker` service: 1. Create a systemd drop-in directory for the `docker` service:
@ -154,7 +165,7 @@ service file, not in the `daemon.json` file or using environment variables.
``` ```
{{< /tab >}} {{< /tab >}}
{{< tab name="rootless mode" >}} {{< tab name="Rootless mode" >}}
1. Create a systemd drop-in directory for the `docker` service: 1. Create a systemd drop-in directory for the `docker` service:

View File

@ -60,7 +60,7 @@ ExecStart=/usr/bin/dockerd
``` ```
There are other times when you might need to configure `systemd` with Docker, There are other times when you might need to configure `systemd` with Docker,
such as [configuring a HTTP or HTTPS proxy](systemd.md#httphttps-proxy). such as [configuring a HTTP or HTTPS proxy](./proxy.md).
> **Note** > **Note**
> >

View File

@ -96,7 +96,7 @@ To create the `docker` group and add your user:
## Configure Docker to start on boot with systemd ## Configure Docker to start on boot with systemd
Many modern Linux distributions use [systemd](../../config/daemon/systemd.md) to Many modern Linux distributions use [systemd](https://systemd.io/) to
manage which services start when the system boots. On Debian and Ubuntu, the manage which services start when the system boots. On Debian and Ubuntu, the
Docker service starts on boot by default. To automatically start Docker and Docker service starts on boot by default. To automatically start Docker and
containerd on boot for other Linux distributions using systemd, run the containerd on boot for other Linux distributions using systemd, run the
@ -114,9 +114,10 @@ $ sudo systemctl disable docker.service
$ sudo systemctl disable containerd.service $ sudo systemctl disable containerd.service
``` ```
If you need to add an HTTP proxy, set a different directory or partition for the You can use systemd unit files to configure the Docker service on startup,
Docker runtime files, or make other customizations, see for example to add an HTTP proxy, set a different directory or partition for the
[customize your systemd Docker daemon options](../../config/daemon/systemd.md). Docker runtime files, or other customizations. For an example, see
[Configure the daemon to use a proxy](../../config/daemon/proxy.md#systemd-unit-file).
## Configure default logging driver ## Configure default logging driver

View File

@ -405,7 +405,7 @@ to learn how to use the `docker scan` command to check if images are vulnerable.
> longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY` > longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY`
> environment variable for handling requests to `https://` URLs. > environment variable for handling requests to `https://` URLs.
> >
> Refer to the [HTTP/HTTPS proxy section](../../config/daemon/systemd.md#httphttps-proxy) > Refer to [Configure the daemon to use a proxy](../../config/daemon/proxy.md)
> to learn how to configure the Docker Daemon to use a proxy server. > to learn how to configure the Docker Daemon to use a proxy server.
{ .important } { .important }
@ -435,7 +435,7 @@ to learn how to use the `docker scan` command to check if images are vulnerable.
> longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY` > longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY`
> environment variable for handling requests to `https://` URLs. > environment variable for handling requests to `https://` URLs.
> >
> Refer to the [HTTP/HTTPS proxy section](../../config/daemon/systemd.md#httphttps-proxy) > Refer to the [HTTP/HTTPS proxy section](../../config/daemon/proxy.md#httphttps-proxy)
> to learn how to configure the Docker Daemon to use a proxy server. > to learn how to configure the Docker Daemon to use a proxy server.
{ .important } { .important }
@ -476,7 +476,7 @@ well as updated versions of the containerd.io package.
> longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY` > longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY`
> environment variable for handling requests to `https://` URLs. > environment variable for handling requests to `https://` URLs.
> >
> Refer to the [HTTP/HTTPS proxy section](../../config/daemon/systemd.md#httphttps-proxy) > Refer to the [HTTP/HTTPS proxy section](../../config/daemon/proxy.md#httphttps-proxy)
> to learn how to configure the Docker Daemon to use a proxy server. > to learn how to configure the Docker Daemon to use a proxy server.
{ .important } { .important }
@ -521,7 +521,7 @@ well as updated versions of the containerd.io package.
> longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY` > longer used for TLS (`https://`) connections. Make sure you also set an `$HTTPS_PROXY`
> environment variable for handling requests to `https://` URLs. > environment variable for handling requests to `https://` URLs.
> >
> Refer to the [HTTP/HTTPS proxy section](../../config/daemon/systemd.md#httphttps-proxy) > Refer to the [HTTP/HTTPS proxy section](../../config/daemon/proxy.md#httphttps-proxy)
> to learn how to configure the Docker Daemon to use a proxy server. > to learn how to configure the Docker Daemon to use a proxy server.
{ .important } { .important }

View File

@ -14,7 +14,7 @@ For instructions on configuring Docker Desktop to use HTTP/HTTPS proxies, see
[proxies on Linux](../desktop/settings/linux.md#proxies). [proxies on Linux](../desktop/settings/linux.md#proxies).
If you're running Docker Engine without Docker Desktop, refer to If you're running Docker Engine without Docker Desktop, refer to
[Configure the Docker daemon to use a proxy server](../config/daemon/systemd.md#httphttps-proxy) [Configure the Docker daemon to use a proxy](../config/daemon/proxy.md)
to learn how to configure a proxy server for the Docker daemon (`dockerd`) itself. to learn how to configure a proxy server for the Docker daemon (`dockerd`) itself.
If your container needs to use an HTTP, HTTPS, or FTP proxy server, you can If your container needs to use an HTTP, HTTPS, or FTP proxy server, you can
@ -79,7 +79,7 @@ These settings are used to configure proxy environment variables for containers
only, and not used as proxy settings for the Docker CLI or the Docker Engine only, and not used as proxy settings for the Docker CLI or the Docker Engine
itself. itself.
Refer to the [environment variables](/engine/reference/commandline/cli/#environment-variables) Refer to the [environment variables](/engine/reference/commandline/cli/#environment-variables)
and [configure the Docker daemon to use a proxy server](../config/daemon/systemd.md#httphttps-proxy) and [configure the Docker daemon to use a proxy server](../config/daemon/proxy.md#httphttps-proxy)
sections for configuring proxy settings for the CLI and daemon. sections for configuring proxy settings for the CLI and daemon.
### Run containers with a proxy configuration ### Run containers with a proxy configuration

View File

@ -1639,8 +1639,8 @@ Manuals:
title: Start the daemon title: Start the daemon
- path: /config/daemon/ - path: /config/daemon/
title: Configure the daemon title: Configure the daemon
- path: /config/daemon/systemd/ - path: /config/daemon/proxy/
title: Configure with systemd title: HTTP proxy
- path: /config/containers/live-restore/ - path: /config/containers/live-restore/
title: Live restore title: Live restore
- path: /config/daemon/troubleshoot/ - path: /config/daemon/troubleshoot/