你好,游客 登录 注册 搜索
背景:
阅读新闻

CentOS 7 Docker 搭建私有仓库 registry

[日期:2015-10-21] 来源:Linux社区  作者:翟军铭 [字体: ]

环境规划:

  • 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下, 两个目录下都有!

·registry的默认存储路径是/tmp/registry,只是个临时目录,一段时间之后就会消失

·所以使用-v参数,指定个本地持久的路径,

[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

更多Docker相关教程见以下内容

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm 

Ubuntu 14.04安装Docker  http://www.linuxidc.com/linux/2014-08/105656.htm 

Ubuntu使用VNC运行基于Docker的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm

阿里云CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm 

Ubuntu 15.04下安装Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm 

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm 

在 Ubuntu 15.04 上如何安装Docker及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm

Docker 的详细介绍请点这里
Docker 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2015-10/124332.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款