`
frank1998819
  • 浏览: 751576 次
  • 性别: Icon_minigender_1
  • 来自: 南京
文章分类
社区版块
存档分类

CentOS7搭建Docker私有仓库(转)

 
阅读更多

学习Docker的过程中Docker的私有仓库一直没能成功,就是因为CentOS 6.x和CentOS 7默认引入了支持https认证,每次在push和pull的时候都会报错,今天是周末,利用一天的时间反复测试和网上案列的整合,总算是成功了,也借此 机会对学习Docker的朋友有所帮助。

个人的愚见:博友在练习的时候建议用CentOS 7.x系统,不建议用CentOS 6.x系统

 

一、准备

地址规划:

Docker私有仓库地址:192.168.0.109
Docker客户端地址:192.168.0.110

1、激活网卡

# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728
修改此行
ONBOOT=yes
# /etc/init.d/network restart

2、关闭本地防火墙并设置开机不自启动

# systemctl stop firewalld.service
# systemctl disable firewalld.service

3、关闭本地selinux防火墙

 
# vi /etc/sysconfig/selinux 
SELINUX=disabled
# setenforce 0   

4、安装ifconfig工具

 
# yum install net-tools

二、安装

1、安装docker

# yum install docker
# yum upgrade device-mapper-libs
# 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
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/registry   latest              24dd746e9b9f        3 days ago          413.8 MB

3、基于私有仓库镜像运行容器

[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        0.0.0.0:5000->5000/tcp   serene_hopper

4、访问私有仓库

[root@localhost ~]# curl 127.0.0.1:5000/v1/search
{"num_results": 0, "query""""results": []} //私有仓库为空,没有提交新镜像到仓库中

5、从Docker Hub上下载一个ssh镜像

[root@localhost ~]# docker search -s 10 ssh
NAME                              DESCRIPTION   STARS     OFFICIAL   AUTOMATED
docker.io: docker.io/fedora/ssh                 18                   [OK]
[root@localhost ~]# docker pull fedora/ssh
Trying to pull repository docker.io/fedora/ssh ...
2aeb2b6d9705: Download complete 
511136ea3c5a: Download complete 
00a0c78eeb6d: Download complete 
834629358fe2: Download complete 
571e8a51403c: Download complete 
87d5d42e693c: Download complete 
92b5ef05fe68: Download complete 
92d3910dc33c: Download complete 
cf2e9fa11368: Download complete 
Status: Downloaded newer image for docker.io/fedora/ssh:latest
[root@localhost ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/registry     latest              24dd746e9b9f        3 days ago          413.8 MB
docker.io/fedora/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB

6、创建镜像链接或为基础镜像打个标签

[root@localhost ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh
[root@localhost ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/registry     latest              24dd746e9b9f        3 days ago          413.8 MB
docker.io/fedora/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB
127.0.0.1:5000/ssh     latest              2aeb2b6d9705        9 days ago          254.4 MB

7、修改Docker配置文件制定私有仓库url

[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--selinux-enabled --insecure-registry 192.168.0.109:5000'
[root@localhost ~]# service docker restart
Redirecting to /bin/systemctl restart  docker.service

8、提交镜像到本地私有仓库中

[root@localhost ~]# docker push 127.0.0.1:5000/ssh
The push refers to a repository [127.0.0.1:5000/ssh] (len: 1)
Sending image list
Pushing repository 127.0.0.1:5000/ssh (1 tags)
511136ea3c5a: Image successfully pushed 
00a0c78eeb6d: Image successfully pushed 
834629358fe2: Image successfully pushed 
571e8a51403c: Image successfully pushed 
87d5d42e693c: Image successfully pushed 
92b5ef05fe68: Image successfully pushed 
92d3910dc33c: Image successfully pushed 
cf2e9fa11368: Image successfully pushed 
2aeb2b6d9705: Image successfully pushed 
Pushing tag for rev [2aeb2b6d9705] on {http://127.0.0.1:5000/v1/repositories/ssh/tags/latest}

9、查看私有仓库是否存在对应的镜像

[root@localhost ~]# curl 127.0.0.1:5000/v1/search
{"num_results": 1, "query""""results": [{"description""""name""library/ssh"}]}

10、查看镜像的存储目录和文件

[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客户端

[root@localhost ~]# ssh root@192.168.0.110
The authenticity of host '192.168.0.110 (192.168.0.110)' can't be established.
ECDSA key fingerprint is 5b:81:4b:66:d6:dd:48:16:9f:85:58:72:21:bd:ba:39.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.110' (ECDSA) to the list of known hosts.
root@192.168.0.110's password: 
Last login: Sun Apr 26 14:39:51 2015 from 192.168.0.103

2、修改Docker配置文件

[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--selinux-enabled --insecure-registry 192.168.0.109:5000'        //添加私有仓库地址
[root@localhost ~]# service docker restart
Redirecting to /bin/systemctl restart  docker.service

3、从私有仓库中下载已有的镜像

[root@localhost ~]# docker pull 192.168.0.109:5000/ssh
Trying to pull repository 192.168.0.109:5000/ssh ...
2aeb2b6d9705: Download complete 
511136ea3c5a: Download complete 
00a0c78eeb6d: Download complete 
834629358fe2: Download complete 
571e8a51403c: Download complete 
87d5d42e693c: Download complete 
92b5ef05fe68: Download complete 
92d3910dc33c: Download complete 
cf2e9fa11368: Download complete 
Status: Downloaded newer image for 192.168.0.109:5000/ssh:latest
[root@localhost ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
192.168.0.109:5000/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB

四、浏览器访问仓库

wKioL1U8yD2CICJXAACRXA3Ij1w707.jpg

本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1638770

分享到:
评论

相关推荐

    Centos 7中Docker私有仓库的搭建方法

    本篇文章主要介绍了Centos 7中Docker私有仓库的搭建方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    详解CentOS 7 : Docker私有仓库搭建和使用

    本篇文章主要介绍了详解CentOS 7 : Docker私有仓库搭建和使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    docker私有仓库搭建

    centos7搭建任意版本的docker以及建立自己的私有仓库registry,已实践!

    Docker搭建私有镜像仓库的方法

    和Mavan的管理一样,Dockers不仅提供了一个中央仓库,同时也允许我们使用registry搭建本地私有仓库。 使用私有仓库有许多优点: 节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库...

    CentOS7.2服务器上搭建Docker私有镜像仓库操作示例

    本文实例讲述了CentOS7.2服务器上搭建Docker私有镜像仓库操作。分享给大家供大家参考,具体如下: 鉴于国内pull镜像的速度较慢,很有必要搭建docker私有或者本地镜像仓库。 安装docker # yum -y install docker #...

    centos7下安装Docker及私有仓库registry服务器安装.pdf

    centos7下安装docker和私有仓库,在自己单位搭建完成,以此为例,给大家借鉴。

    centos7系统下搭建docker本地镜像仓库的方法

    本篇文章主要介绍了CentOS 7 : Docker私有仓库搭建和使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

    centos7搭建docker私人仓库的方法(kubernetes)

    这篇文章讲解如何用docker提供的registry镜像来搭建自己的镜像仓库。 不添加ssl认证的仓库 下面用registry:2.6.2镜像创建docker仓库。 将宿主机的5000端口映射到容器的5000端口。 将宿主机/mnt/registry挂在到...

    docker搭建私有仓库.txt

    docker私有仓库在虚拟机上创建私有仓库,环境centos6.0

    docker搭建基于局域网的私有仓库(带用户权限)

        两台装有docker的Centos7虚拟机(尽量保证docker的版本都一致)      虚拟机一:192.168.0.124 用作私有仓库      虚拟机二:192.168.0.122 普通用户机 搭建:     1、私有仓库是

    搭建Docker私有仓库(自签名方式)

    为了能集中管理我们创建好的镜像,方便部署服务,我们会创建私有的Docker仓库。通读了一遍官方文档,Docker为了确保安全使用TLS,需要CA认证,认证时间长的要钱啊,免费过期时间太短,还是用自签名比较简单。 准备...

    详解centos7 docker1.12安装私有仓库

    1、安装docker:我用的是centos7 操作系统 3.10,虽然可以直接yum install docker 但安装的docker1.10 稳定版,生产环境要用1.12的所以需要配置下yum源。 操作步骤: 1、 配置yum源 touch /etc/yum.repos.d/...

    Docker私有仓库Registry部署的实现

    随着docker使用的镜像越来越多,就需要有一个保存...两台CentOS7.4,一台为Docker私有仓库;另一台为Docker客户端,测试使用; 两台服务器都需要安装Docker服务,请参考博文:安装Docker.v19版本 1、配置registry私有

    CentOS7部署安装私有Docker Registry

    私有Docker Registry搭建 依据《CentOS7实验机模板搭建部署》部署一台实验机:registry 192.168.77.200 依据《CentOS7部署安装Docker和Docker Compose工具简录》部署安装Docker环境 # 运行registry容器,并将其数据...

Global site tag (gtag.js) - Google Analytics