说明
设置代理可以用于Docker拉取镜像
修改配置文件
修改配置文件/etc/docker/daemon.json,没有的话创建一个该文件、
文件中添加内容如下
{
"proxies": {
"http-proxy": "socks5://127.0.0.1:1080",
"https-proxy": "socks5://127.0.0.1:1080",
"no-proxy": "*.test.example.com,.example.org,127.0.0.0/8"
}
}
重启docker
sudo systemctl restart docker
查看配置是否成功
使用docekr info查看下
➜ ~ sudo docker info
Client: Docker Engine - Community
Version: 26.1.4
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.14.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.27.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 4
Running: 0
Paused: 0
Stopped: 4
Images: 7
Server Version: 26.1.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.8.0-35-generic
Operating System: Ubuntu 24.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 28
Total Memory: 62.63GiB
Name: ubuntu
ID: 1e14773c-fed7-44e2-ab10-1043bb9c6993
Docker Root Dir: /var/lib/docker
Debug Mode: false
## 配置成功会有如下显示
HTTP Proxy: socks5://127.0.0.1:1080
HTTPS Proxy: socks5://127.0.0.1:1080
No Proxy: *.test.example.com,.example.org,127.0.0.0/8
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
测试
➜ ~ sudo docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d1b0b5888fbb59111dbf2b3ed698489c41046cb9d6d61743e37ef8d9f3dda06f
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest