admin 发表于 2021-7-23 11:46:53

docker配置本地代理proxy

# cat /etc/systemd/system/docker.service.d/proxy.conf

Environment="HTTP_PROXY=http://192.168.2.158:7890/"
Environment="HTTPS_PROXY=http://192.168.2.158:7890/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

重启docker服务生效: systemctl restart docker.service
# docker info
Client:
Context:    default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2
runc version: v1.0.0-0-g84113ee
init version: de40ad0
Security Options:
seccomp
   Profile: default
Kernel Version: 3.10.0-1160.31.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 32
Total Memory: 125.7GiB
Name: compute01
ID: AFW3:TFZH:XZUS:OH53:CCMW:WWK5:54TT:7QUV:TWQB:D3YZ:34HT:467T
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http://192.168.2.158:7890/
HTTPS Proxy: http://192.168.2.158:7890/
No Proxy: localhost,127.0.0.1,.example.com
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false


当不再使用时,我们需要取消这个代理:# cat /etc/systemd/system/docker.service.d/proxy.conf
#
#Environment="HTTP_PROXY=http://192.168.2.158:7890/"
#Environment="HTTPS_PROXY=http://192.168.2.158:7890/"
#Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

重启docker服务:# systemctl daemon-reload systemctl restart docker.service

# docker info
Client:
Context:    default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2
runc version: v1.0.0-0-g84113ee
init version: de40ad0
Security Options:
seccomp
   Profile: default
Kernel Version: 3.10.0-1160.31.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 32
Total Memory: 125.7GiB
Name: compute01
ID: AFW3:TFZH:XZUS:OH53:CCMW:WWK5:54TT:7QUV:TWQB:D3YZ:34HT:467T
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
页: [1]
查看完整版本: docker配置本地代理proxy