CentOS环境下Docker私有仓库搭建

本文讲述如何搭建docker私有仓库。

 

有了docker hub,为什么还要搭建docker私有仓库?

1、性能考虑:docker hub的访问要通过互联网,性能太低。

2、安全性:更多的时候,镜像不想被外部的人获取,虽然可以在docker hub上申请私有repository,但是需要付费。

 

系统环境:CentOS release 6.7 (Final)

IP:100.90.61.14

 

  • 安装docker

如下操作是在root用户下

yum -y install docker-io

启动docker

service docker start   # 启动docker
service docker stop    # 停止docker
service docker restart # 重启docker

 

  • 搭建docker私有仓库

搭建docker私有仓库也是通过docker,真是就地取材。

1、首先下载registry镜像

docker pull registry:2

说明:

这里下载的是最新版本2。

 

2、启动registry镜像的容器

docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2

说明:

-d ==> 作为daemon进程启动,也就是后台启动

-v /myregistry:/tmp/registry ==> 默认情况下,会将仓库存放于容器内的/tmp/registry目录下,指定本地目录/myregistry挂载到容器,可以防止容器意外停止后镜像的丢失。

-p 5000:5000 ==> 前一个5000是host的端口,后一个是容器的端口。这里是将容器的5000端口映射到host的5000端口。

 

3、配置https权限支持

修改/etc/sysconfig/docker,我的文件内容如下

# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

other_args="--exec-driver=lxc --selinux-enabled --insecure-registry 100.90.61.14:5000"
DOCKER_CERT_PATH=/etc/docker

# Resolves: rhbz#1176302 (docker issue #407)
DOCKER_NOWARN_KERNEL_VERSION=1

# Location used for temporary files, such as those created by
# # docker load and build operations. Default is /var/lib/docker/tmp
# # Can be overriden by setting the following environment variable.
# # DOCKER_TMPDIR=/var/tmp
#
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://2a5b5ce4.m.daocloud.io

说明:

--insecure-registry 100.90.61.14:5000,表示开启5000端口的非安全模式,也就是http模式。

重启docker服务

service docker restart

 

 

  • 上传镜像到私有registry

先下载一个httpd镜像作为示例

docker pull httpd

修改一下该镜像的tag

# docker tag httpd 100.90.61.14:5000/kangaroo/httpd:v1

说明:

1)我们在镜像前面加上了运行私有registry的ip:port,这是必须的,只有访问docker hub的时候可以忽略ip:port。

2)kangaroo是我的网名,这里加上予以区分用户。

 

上传

上传镜像到私有registry

# docker push 100.90.61.14:5000/kangaroo/httpd:v1

在私有registry上查看镜像

# curl -XGET http://100.90.61.14:5000/v2/_catalog

{"repositories":["kangaroo/httpd"]}

 

下载

从私有registry上下载镜像

删除本地镜像

docker rmi 100.90.61.14:5000/kangaroo/httpd:v1

从私有registry上下载

docker pull 100.90.61.14:5000/kangaroo/httpd:v1

查看本地镜像,可以看到已经拉下来了。

# docker images
100.90.61.14:5000/kangaroo/httpd   v1                  91199e851c7a        4 weeks ago         177.3 MB

 

posted @ 2017-12-06 20:58  扎心了老铁  阅读(9701)  评论(0编辑  收藏  举报