Docker 使用国内加速器

来源:互联网 发布:禅道 mysql数据库连接 编辑:程序博客网 时间:2024/05/17 09:16

Docker在国内的窘境

Docker革命性的提高了开发运维效率,真正实现了DevOps的概念,将环境变得标准化,在很大程度上改变了运维的发展。

然而,在国内使用Docker源,速度会非常慢,而且很多时候干脆连不上服务器:

Pulling repository docker.io/library/lavadiablodocker-xwikiNetwork timed out while trying to connect to https://index.docker.io/v1/repositories/library/lavadiablodocker-xwiki/images. You may want to check your internet connection or if you are behind a proxy 

像yum,apt-get,anaconda,pip,npm,这些包管理工具都有很好的国内源替代产品,基本能够完全将全量数据同步到国内,然而dockerhub上的全量数据,在国内始终没有找到好的替代产品。

国内相关的几款产品,能够在很大程度上改变这一情况,但是仅仅是缓解,而不是解决。

  1. Daocloud 这是一款很棒的互联网产品,最近融资情况也很顺利。其提供了一个国内的镜像市场,以及docker本身的安装源。对于获取image速度的问题,Daocloud还提供了一个加速器,速度还不错。但是美中不足,一是并没有全量同步dockerhub上的数据,很多docker官方的镜像都找不到,dockerhub上很多第三方提供的内容更是没有同步,二是无法利用第三方的Docker文件直接在服务器端构建镜像。
  2. 阿里云开发者 相比之下,功能做的更加扎实。但不足同样在于,没有全量同步dockerhub上的镜像。估计是此项目在阿里内部没有受到足够的重视,资源分配不足造成。阿里云提供私有加速器地址,这些加速器能够加速docker官方的镜像拉取,另外还提供海外机器构建服务,构建之后可以在国内从阿里云中拉取。

使用加速器

使用加速器的方法为,在docker服务启动时,加入参数 –registry-mirror=XXX。在加速器页面中,能看到这两个网站都准备了一键修改脚本,自动替换。

然而,对于有些版本的 服务器,这些脚本会失效。

例如,笔者使用CentOS7,从docker-engine包中安装。这时启动docker服务的命令为 dockerd,而不是docker -d,与脚本中的不同。针对这一问题,笔者采取手动修改docker启动脚本的方式来增加参数即可。

笔者是将/etc/systemd/system/docker.service 文件做如下修改
(如果找不到这个文件,也可以在以下位置找到:/lib/systemd/system/docker.service)

[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network.target[Service]Type=notify# the default is not to use systemd for cgroups because the delegate issues still# exists and systemd currently does not support the cgroup feature set required# for containers run by dockerExecStart=/usr/bin/dockerd --registry-mirror=https://u1qbyfsc.mirror.aliyuncs.comExecReload=/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.LimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMax=infinityTimeoutStartSec=0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=process[Install]WantedBy=multi-user.target

其中ExecStart=/usr/bin/dockerd 替换成了 ExecStart=/usr/bin/dockerd --registry-mirror=https://u1qbyfsc.mirror.aliyuncs.com

这样,拉取docker官方源时,即可使用非常明显的加速。

另外,阿里云还提供云端构建功能。在dockerhub上看到的第三方image,经常作者会提供构建文件。找到这些文件,放到github等代码托管平台上,在阿里云的镜像仓库中新建一个镜像,导入构建文件,再在阿里云控制台上操作,即可使用阿里云海外主机进行构建,之后供自己拉取到国内的主机上。

0 0