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

[[email protected] ~]# 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

[[email protected] ~]# docker images

REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

docker.io/registry   latest              24dd746e9b9f        3 days ago          413.8 MB

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

[[email protected] ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry

bb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95

[[email protected] ~]# 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、访问私有仓库

[[email protected] ~]# curl 127.0.0.1:5000/v1/search

{"num_results": 0, "query""""results": []} //私有仓库为空,没有提交新镜像到仓库中

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

[[email protected] ~]# docker search -s 10 ssh

NAME                              DESCRIPTION   STARS     OFFICIAL   AUTOMATED

docker.io: docker.io/fedora/ssh                 18                   [OK]

[[email protected] ~]# 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

[[email protected] ~]# 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、创建镜像链接或为基础镜像打个标签

[[email protected] ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh

[[email protected] ~]# 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

[[email protected] ~]# vim /etc/sysconfig/docker

修改此行

OPTIONS=‘--selinux-enabled --insecure-registry 192.168.0.109:5000‘

[[email protected] ~]# service docker restart

Redirecting to /bin/systemctl restart  docker.service

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

[[email protected] ~]# 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、查看私有仓库是否存在对应的镜像

[[email protected] ~]# curl 127.0.0.1:5000/v1/search

{"num_results": 1, "query""""results": [{"description""""name""library/ssh"}]}

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

[[email protected] ~]# tree /opt/data/registry/repositories/

/opt/data/registry/repositories/

└── library

    └── ssh

        ├── _index_images

        ├── json

        ├── tag_latest

        └── taglatest_json

2 directories, 4 files

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

1、登陆另外一台Docker客户端

[[email protected] ~]# ssh [email protected]

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.

[email protected]‘s password: 

Last login: Sun Apr 26 14:39:51 2015 from 192.168.0.103

2、修改Docker配置文件

[[email protected] ~]# vim /etc/sysconfig/docker

修改此行

OPTIONS=‘--selinux-enabled --insecure-registry 192.168.0.109:5000‘        //添加私有仓库地址

[[email protected] ~]# service docker restart

Redirecting to /bin/systemctl restart  docker.service

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

[[email protected] ~]# 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

[[email protected] ~]# docker images

REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

192.168.0.109:5000/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB

四、浏览器访问仓库

时间: 2025-01-02 06:54:41

CentOS7搭建Docker私有仓库的相关文章

搭建docker私有仓库

安装Docker Docker的安装请参考官网(http://www.docker.com),非常详细的介绍了各个操作系统的部署过程. 对于CentOS 7.x操作系统的在线安装Docker,请参考如下:https://docs.docker.com/engine/installation/linux/centos 搭建Docker私有仓库 Docker官方提供了一个公有的registry叫做Docker Hub.但是企业内部可能有些镜像还是不方便放到公网上去,所以docker也提供了regis

手把手教你搭建Docker私有仓库

章节一:centos7 docker安装和使用_入门教程 章节二:使用docker部署Asp.net core web应用程序 有了前面的基础,接下来的操作就会比较简单了. 先准备两台虚拟机: Docker客户端:192.168.1.160 Docker私有仓库服务器:192.168.1.161 两台机器上都配好yum源,安装好docker,设置好docker加速器 1.在服务端192.168.1.161上拉取仓库镜像:registry [[email protected] ~]# docker

CentOS 7搭建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

ubuntu16.04搭建docker私有仓库

ubuntu:16.04 docker:18.06.0 docker仓库服务器:192.168.83.102 docker测试客户端:192.168.83.101 --------------------------------------分割线-------------------------------------- 首先按照官网安装好docker:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 安装好docker之后首先pul

centos下搭建docker私有仓库

目前Docker Registry已经升级到了v2,最新版的Docker已不再支持v1.Registry v2使用Go语言编写,在性能和安全性上做了很多优化,重新设计了镜像的存储格式.此文档是在v1的基础上写的,如果需要安装registry v2,只需下载registry:2.2即可,或者可以下载后面的安装脚本运行安装. 一.下载registry镜像 docker pull registry 二.启动私有仓库容器,默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被

Centos7搭建Harbor私有仓库(一)

1 说明 前文Centos7搭建DockerRegistry介绍了DockerRegistry的搭建,但它没有UI页面,因此选择Harbor 以下基于镜像CentOS-7-x86_64-Minimal-1804进行搭建 均已root用户进行操作 2 安装docker和docker-compose 参见Centos7安装DockerCE安装Docker引擎 2.1 安装docker-compose 1.下载docker-compose的最新版本 curl -L "https://github.co

Docker入门-搭建docker私有仓库

Docker Hub 目前Docker官方维护了一个公共仓库Docker Hub,其中已经包括了数量超过15000个镜像.大部分需求都可以通过在Docker Hub中直接下载镜像来使用. 注册登录 可以在https://hub.docker.com 免费注册一个Docker账号.在命令行执行docker login输入用户名及密码来完成在命令行界面登记Docker Hub.你可以通过docker logout退出登录. 拉取镜像 可以通过docker search命令来查找官方仓库中的镜像,并利

CentOS 搭建docker私有仓库实践

前言 由于目前大多数的镜像下载网站都是在国外站点,国内用户在下镜像的时候就时常遇到下载速度超慢的情况:而且在将Docker应用到生产环境的过 程中,还会面临下载过来的Docker镜像是否安全的问题. 因些在生产环境下搭建私有的Docker Registry,就是一个一举二得的方案了.但目前国内的大多数企业使用的发行版,为Redhat体系,其中又以Centos环境居多.而网上的资料和出版的书籍在介绍Docker的时候都是以ubuntu为基础进行讲解和配置,而CentOS6.x以上版本访问私有的 D

centos7 安装docker私有仓库

1.docker 的私服配置文件位置在 /usr/lib/systemd/system/docker.service #vim /usr/lib/systemd/system/docker.service 添加以下内容 2.重启docker systemctl restart docker 3.下载registry #docker pull registry:2 4.启动registry #docker run -d -ti --restart always --name docker-regi