docker设置镜像加速
1,使用以下命令直接从该镜像加速地址进行拉取。
命令:docker pull registry.docker-cn.com/myname/myrepo:mytag
例:docker pull registry.docker-cn.com/library/ubuntu:16.10
注:除非修改了Docker守护进程的–registry-mirror参数,
否则需要完整地指定镜像的名称。例,library/ubuntu、library/redis、library/nginx。
2,使用 --registry-mirror配置Docker守护进程加速。
★临时生效:
Docker守护进程启动时传入 --registry-mirror 参数:
# docker --registry-mirror=https://xxxxxxxx.mirror.aliyuncs.com daemon
★永久生效:
通过配置文件启动Docker,修改/etc/docker/daemon.json 文件并添加上 registry-mirrors 键值。
vim /etc/docker/daemon.json
◆配置镜像加速1:
阿里的镜像地址:https://xxxxxxxx.mirror.aliyuncs.com(私人账号地址)
{
"registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
•可以配置多个镜像加速地址,用逗号分隔。
"registry-mirrors":["https://registry.docker.cn.com","https://xxxxxxxx.mirror.aliyuncs.com"]
◆配置镜像加速2:
文档参考:https://www.daocloud.io/mirror
Linux下命令:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
{
"registry-mirrors": ["https://xxxxxxxx.m.daocloud.io"]
}
★临时使用:
•使用163的docker仓库,拉取镜像
网易的镜像地址:http://hub.c.163.com
docker pull hub.c.163.com/public/centos:7.2
3,修改保存后,重启Docker以使配置生效。
sudo systemctl daemon-reload
sudo systemctl restart docker
4,查看配置是否生效。
执行docker info,查看是否含有如下信息:
Registry Mirrors:
https://xxxxxxxx.mirror.aliyuncs.com/
5,补充
docker daemon.json的完整配置示例及说明参照:https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
{ "authorization-plugins": [], "data-root": "", "dns": [], "dns-opts": [], "dns-search": [], "exec-opts": [], "exec-root": "", "experimental": false, "features": {}, "storage-driver": "", "storage-opts": [], "labels": [], "live-restore": true, "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file":"5", "labels": "somelabel", "env": "os,customer" }, "mtu": 0, "pidfile": "", "cluster-store": "", "cluster-store-opts": {}, "cluster-advertise": "", "max-concurrent-downloads": 3, "max-concurrent-uploads": 5, "default-shm-size": "64M", "shutdown-timeout": 15, "debug": true, "hosts": [], "log-level": "", "tls": true, "tlsverify": true, "tlscacert": "", "tlscert": "", "tlskey": "", "swarm-default-advertise-addr": "", "api-cors-header": "", "selinux-enabled": false, "userns-remap": "", "group": "", "cgroup-parent": "", "default-ulimits": { "nofile": { "Name": "nofile", "Hard": 64000, "Soft": 64000 } }, "init": false, "init-path": "/usr/libexec/docker-init", "ipv6": false, "iptables": false, "ip-forward": false, "ip-masq": false, "userland-proxy": false, "userland-proxy-path": "/usr/libexec/docker-proxy", "ip": "0.0.0.0", "bridge": "", "bip": "", "fixed-cidr": "", "fixed-cidr-v6": "", "default-gateway": "", "default-gateway-v6": "", "icc": false, "raw-logs": false, "allow-nondistributable-artifacts": [], "registry-mirrors": [], "seccomp-profile": "", "insecure-registries": [], "no-new-privileges": false, "default-runtime": "runc", "oom-score-adjust": -500, "node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"], "runtimes": { "cc-runtime": { "path": "/usr/bin/cc-runtime" }, "custom": { "path": "/usr/local/bin/my-runc-replacement", "runtimeArgs": [ "--debug" ] } }, "default-address-pools":[ {"base":"172.80.0.0/16","size":24}, {"base":"172.90.0.0/16","size":24} ] }