因为网速和大中华局域网效果,使得咱们在DockerHub下载镜像的速度很慢,甚至一些国内的镜像仓库,也感受速度不是很好。因此,颇有必要在本地或者一个咱们访问很快速的地方(本身的云服务器)搭建一套镜像仓库。有了这样一个仓库,不只能够提升下载速度,并且能够增长咱们个性化定制的镜像,以备后续使用。这篇将介绍怎样搭建本地镜像。docker
话外篇,配置docker代理ubuntu
若是有一个很快的代理,固然也能够直接经过配置docker代理,以达到快速下载镜像的目的。在搭建本地镜像的过程也须要从DockerHub上下载完整镜像文件,若是访问缓慢的话,下载将会很是缓慢。设置代理的方法很是简单,这里以CentOS6.5为例。缓存
找到/etc/default/docker,打开编辑,找到下面export http_proxy部分,去掉注释并修改成本身的代理便可。bash
# Docker Upstart and SysVinit configuration file # Customize location of Docker binary (especially for development testing). #DOCKER="/usr/local/bin/docker" # Use DOCKER_OPTS to modify the daemon startup options. #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" # If you need Docker to use an HTTP proxy, it can also be specified here. export http_proxy="http://xxxx:port" # This is also a handy place to tweak where Docker's temporary files go. #export TMPDIR="/mnt/bigdrive/docker-tmp" DOCKER_OPTS="--insecure-registry dl.dockerpool.com:5000"
建立私有仓库服务器
本文记录以Docker官方提供的镜像Registry 建立本地私有仓库,建立方式和启动一个普通镜像的方式是同样。curl
1.在私有仓库服务器快速建立镜像仓库,运行以下代码:ide
docker run -p 5000:5000 registry:2.0
运行上述命令后,会从DockerHub上拉取registry镜像并在本地启动Registry服务,并监听5000端口。 url
2.列出本地镜像代理
docker images
能够看到registry的镜像和一个本地ubuntu:12.04的镜像blog
3.从新标记一个本地镜像为私有仓库的版本,这里将本地的ubuntu 12.04标记为localhost:5000/ubuntu:1204。
docker tag ubuntu:12.04 localhost:5000/ubuntu:1204
再次查看镜像能够看到多了一个标记为localhost:5000/ubuntu:1204的镜像
4.将本地镜像推送到本地仓库中
docker push localhost:5000/ubuntu:1204
5.查看本地仓库中的镜像列表
curl http://localhost:5000/v2/ubuntu/tags/list
结果以下:
{"name":"ubuntu","tags":["1204"]}
6.从本地仓库拉取一个镜像,在这以前先执行以下命令移除本地未使用的镜像,保证从本地仓库拉取的镜像不是从缓存中获取。
docker rmi -f $(docker images -q -a )
以后再查看镜像,只剩下registry这个镜像
拉取本地仓库中的镜像
docker pull localhost:5000/ubuntu:1204 Unable to find image 'localhost:5000/ubuntu:1204' locally 1204: Pulling from localhost:5000/ubuntu b796a17a2688: Pull complete 273721eafe54: Pull complete 7dd38dbb5eda: Pull complete 32190de3770a: Already exists
以后查看镜像以下:
最后正常启动
docker run --name mytestubuntu localhost:5000/ubuntu:1204
欢迎关注公众号「gushidefengzheng」古时的风筝