Ubuntu Docker代理和镜像配置方法

Docker 配置镜像#

1
vi /etc/docker/daemon.json

增加 “registry-mirrors”:

1
2
3
4
5
6
7
8
{
// ... 省略其他配置
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"https://reg-mirror.qiniu.com"
]
}

然后重启 docker 服务:
systemctl restart docker.service

Docker 代理配置#

1
2
3
4
5
6
7
$> cd /etc/systemd/system/docker.service.d # 此目录如果不存在则请手动创建
$> ls -al ./

drwxr-xr-x 2 root root 4096 Feb 28 18:22 .
drwxr-xr-x 17 root root 4096 Feb 24 15:53 ..
-rw-r--r-- 1 root root 157 Feb 28 18:21 http-proxy.conf
-rw-r--r-- 1 root root 158 Feb 28 18:22 https-proxy.conf

目录/etc/systemd/system/docker.service.d不存在的话请手动创建,并在此目录下创建两个文件:http-proxy.confhttps-proxy.conf;
http-proxy.conf增加以下内容:

1
2
[Service]
Environment="HTTP_PROXY=http://192.168.31.100:8118/" "NO_PROXY=localhost,127.0.0.1,*.edu.cn,*.docker-cn.com,*.qiniu.com"

https-proxy.conf增加以下内容:

1
2
[Service]
Environment="HTTPS_PROXY=http://192.168.31.100:8118/" "NO_PROXY=localhost,127.0.0.1,*.edu.cn,*.docker-cn.com,*.qiniu.com"

重启 Docker服务:

1
2
$> systemctl daemon-reload
$> systemctl restart docker.service