• -------------------------------------------------------------
  • ====================================

docker创建私有仓库

docker dewbay 5年前 (2019-05-08) 1970次浏览 已收录 0个评论 扫描二维码

由于网速和大中华局域网效果,使得我们在 DockerHub 下载镜像的速度很慢,甚至一些国内的镜像仓库,也感觉速度不是很好。所以,很有必要在本地或者一个我们访问很快速的地方(自己的云服务器)搭建一套镜像仓库。有了这样一个仓库,不仅可以提高下载速度,而且可以增加我们个性化定制的镜像,以备后续使用。这篇将介绍怎样搭建本地镜像。

话外篇,配置docker代理

如果有一个很快的代理,当然也可以直接通过配置docker代理,以达到快速下载镜像的目的。在搭建本地镜像的过程也需要从 DockerHub 上下载完整镜像文件,如果访问缓慢的话,下载将会非常缓慢。设置代理的方法非常简单,这里以 CentOS6.5 为例。

找到/etc/default/docker,打开编辑,找到下面 export http_proxy 部分,去掉注释并修改为自己的代理即可。

123456789# 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 创建本地私有仓库,创建方式和启动一个普通镜像的方式是一样。

1.在私有仓库服务器快速创建镜像仓库,运行如下代码:

1docker run -p 5000:5000 registry:2.0

运行上述命令后,会从 DockerHub 上拉取 registry 镜像并在本地启动 Registry 服务,并监听 5000 端口。 

2.列出本地镜像

1docker images
docker创建私有仓库

可以看到 registry 的镜像和一个本地 ubuntu:12.04 的镜像

3.重新标记一个本地镜像为私有仓库的版本,这里将本地的 ubuntu 12.04 标记为 localhost:5000/ubuntu:1204。

1docker tag ubuntu:12.04 localhost:5000/ubuntu:1204

再次查看镜像可以看到多了一个标记为 localhost:5000/ubuntu:1204 的镜像

docker创建私有仓库

4.将本地镜像推送到本地仓库中

1docker push localhost:5000/ubuntu:1204

5.查看本地仓库中的镜像列表

1curl http://localhost:5000/v2/ubuntu/tags/list

结果如下:

1{"name":"ubuntu","tags":["1204"]}

 6.从本地仓库拉取一个镜像,在这之前先执行如下命令移除本地未使用的镜像,保证从本地仓库拉取的镜像不是从缓存中获取。

1docker rmi -f $(docker images -q -a )
docker创建私有仓库

之后再查看镜像,只剩下 registry 这个镜像

拉取本地仓库中的镜像

12345678docker pull localhost:5000/ubuntu:1204 Unable to find image 'localhost:5000/ubuntu:1204' locally1204: Pulling from localhost:5000/ubuntub796a17a2688: Pull complete273721eafe54: Pull complete7dd38dbb5eda: Pull complete32190de3770a: Already exists

之后查看镜像如下:

docker创建私有仓库

最后正常启动

1docker run --name mytestubuntu localhost:5000/ubuntu:1204 

露水湾 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:docker创建私有仓库
喜欢 (0)
[]
分享 (0)
关于作者:
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址