Files
nexus/wiki/concepts/Docker-Daemon-代理.md
2026-04-17 08:38:12 +08:00

37 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Docker Daemon 代理"
type: concept
tags: [docker, proxy]
last_updated: 2026-04-17
---
## Definition
Docker Daemon 代理是指为 Docker 守护进程dockerd配置 HTTP/HTTPS 代理,使 `docker pull``docker push` 等操作能够通过代理服务器访问外部网络。
## Problem
Docker 守护进程由 systemd 启动,不读取普通用户的 shell 环境变量(如 HTTP_PROXY、HTTPS_PROXY因此即使系统级配置了代理Docker 操作仍可能失败。
## Solution
通过 systemd drop-in 配置文件为 Docker Daemon 设置环境变量:
1. 创建配置目录:`sudo mkdir -p /etc/systemd/system/docker.service.d`
2. 创建代理配置文件:`sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf`
3. 添加内容:
```
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:10808/"
Environment="HTTPS_PROXY=http://127.0.0.1:10808/"
Environment="NO_PROXY=localhost,127.0.0.1"
```
4. 重载并重启:`sudo systemctl daemon-reload && sudo systemctl restart docker`
## Verification
```bash
docker info | grep -i proxy
```
## Related Concepts
- [[SOCKS5代理]]SOCKS5 代理协议
- [[透明代理]]:另一种强制流量走代理的机制
- [[科学上网]]:通过代理服务器绕过网络限制访问被封锁网站的技术