关注IT
关注系统玩家

linux下docker 添加registry-mirrors 加速地址

docker有两种方法添加registry-mirrors 加速地址 :

1、在daemon.json 中添加

默认json路径为/etc/docker/daemon.json(linux),%programdata%\docker\config\daemon.json(windows),

linux下用vim编辑器打开文件添加:
"registry-mirrors": [https://um1k3l1w.mirror.aliyuncs.com]
添加好后daemon.json文件应该类似这样*(记得倒数第二行最后的英文逗号和字符串前后的引号):
{
"insecure-registries": ["10.66.21.90:5000"],
"registry-mirrors": ["https://um1k3l1w.mirror.aliyuncs.com"]
}
最后执行:
systemctl daemon-reload && systemctl restart docker

2、通过服务文件添加

通过 systemctl status docker 查看状态时候,会看到加载的一个服务文件,如下:

root@node0:~# systemctl status docker
● docker.service - Docker Application Container Engine
 Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
 Active: active (running) since Sat 2017-05-13 06:28:01 PDT; 22h ago
 Docs: https://docs.docker.com

Ubuntu默认路径为/lib/systemd/system/docker.service,centos默认路径:/usr/lib/systemd/system/docker.service

用vim 打开docker.service文件,找到ExecStart=/usr/bin/dockerd 这一行,在最后添加–registry-mirror=https://um1k3l1w.mirror.aliyuncs.com

# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd   --registry-mirror=https://um1k3l1w.mirror.aliyuncs.com 
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.

最后执行 :

systemctl daemon-reload && systemctl restart docker

以上两种方法均可以配置Registry Mirrors,执行docker info命令,可以查询到以下信息,

Insecure Registries:
 127.0.0.0/8
Registry Mirrors:
 https://um1k3l1w.mirror.aliyuncs.com/
Live Restore Enabled: false

11.1 修正:在docker 1.12.6之前的版本,docker info无法查看到Registry Mirrors: https://um1k3l1w.mirror.aliyuncs.com/  地址。

分享到:更多 ()
喜欢 1
rancher

评论 抢沙发

评论前必须登录!