环境规划:
docker私有仓库地址:192.168.0.167
docker客户端地址 : 192.168.0.167
·关闭防火墙和selinux
systemctl stop firewalld.service systemctl disable firewalld.service # vi /etc/sysconfig/selinux SELINUX=disabled # setenforce 0
服务端
1.安装并启动docker
yum -y install docker service docker start chkconfig docker on
2.拉取本地私有仓库registry
[root@localhost ~]# docker pull registry Trying to pull repository docker.io/registry ... 24dd746e9b9f: Download complete 706766fe1019: Download complete a62a42e77c9c: Download complete 2c014f14d3d9: Download complete b7cf8f0d9e82: Download complete d0b170ebeeab: Download complete 171efc310edf: Download complete 522ed614b07a: Download complete 605ed9113b86: Download complete 22b93b23ebb9: Download complete 2ac557a88fda: Download complete 1f3b4c532640: Download complete 27ebaac643a7: Download complete ce630195cb45: Download complete Status: Downloaded newer image for docker.io/registry:latest
3.查看registry镜像
[root@localhost ~]# docker images docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
4.基于私有仓库镜像运行容器
默认情况下,会将仓库存放于容器的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器的/tmp/registry下
[root@localhost ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry bb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95 root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb2c0d442df9 docker.io/registry:latest "docker-registry" 10 seconds ago Up 7 seconds
5.访问私有仓库
[root@localhost ~]# curl 127.0.0.1:5000/v1/search {"num_results": 0, "query": "", "results": []} #私有仓库为空,没有提交新镜像到仓库中
6.从Docker HUB 上拉取一个镜像测试
[root@localhost ~]#docker pull busybox [root@localhost ~]#docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
7.创建镜像链接为基础镜像打个标签
[root@localhost ~]# docker tag docker.io/busybox 192.168.0.167:5000/busybox [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
8.修改docker配置文件,指定私有仓库url
[root@localhost ~]# vim /etc/sysconfig/docker 修改此行 OPTIONS=‘--insecure-registry 192.168.0.167:5000 ‘ [root@localhost ~]# service docker restart
9.上传镜像到本地私有仓库
docker push 192.168.0.167:5000/busybox
10.查看私有仓库是否有对应的镜像
[root@localhost ~]# curl 192.168.0.167:5000/v1/search {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/busybox"}]}
11.查看镜像的存储目录和文件
[root@localhost ~]# tree /opt/data/registry/repositories/ /opt/data/registry/repositories/ └── library └── ssh ├── _index_images ├── json ├── tag_latest └── taglatest_json 2 directories, 4 files
客户端
1.安装并启动docker
yum -y install docker service docker start chkconfig docker on
2.修改docker配置文件,指定私有仓库url
[root@localhost ~]# vim /etc/sysconfig/docker 修改此行 OPTIONS=‘--insecure-registry 192.168.0.167:5000 ‘ [root@localhost ~]# service docker restart
3.测试,下载刚才上传的镜像
[root@localhost ~]# docker pull 192.168.0.167:5000/busybox [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB docker.io/atcol/docker-registry-ui latest d838355ad903 6 months ago 890.5 MB
本文出自 “翟军铭的linux博客” 博客,请务必保留此出处http://zhaijunming5.blog.51cto.com/10668883/1704454
centos7 docker 搭建私有仓库 registry
原文:http://zhaijunming5.blog.51cto.com/10668883/1704454