Auto-sync: 2026-04-17 08:37
This commit is contained in:
36
wiki/concepts/Docker-Daemon-代理.md
Normal file
36
wiki/concepts/Docker-Daemon-代理.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
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 代理协议
|
||||
- [[透明代理]]:另一种强制流量走代理的机制
|
||||
- [[科学上网]]:通过代理服务器绕过网络限制访问被封锁网站的技术
|
||||
Reference in New Issue
Block a user