Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6847283
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: 虚拟化

2015-10-22 10:10:51

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/            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)  

 14.04安装Docker   

Ubuntu使用VNC运行基于Docker的桌面系统  

阿里云CentOS 6.5 模板上安装 Docker  

Ubuntu 15.04下安装Docker   

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker  

在 Ubuntu 15.04 上如何安装Docker及基本用法 

Docker 的详细介绍
Docker 的下载地址

本文永久更新链接地址

阅读(1095) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~