centos7.2定制属于自己的docker私有库

解决http协议的问题:

方法一:解决HTTPS问题

安装nginx,配置HTTPS协议

方法二:修改docker的配置文件

vim  /etc/default/docker增加

OPTIONS="--insecure-registry 192.168.10.249:5000"


准备配置环境:

主机名     主机IP 服务
docker-images 10.0.0.5 docker    私有库库配置

10.0.0.6 docker    客户端
[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64
[[email protected] ~]# uname -m
x86_64
[[email protected] ~]# uname -a
Linux docker-images 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]#

开始配置(镜像库)

1、关闭防火墙和selinux

[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld   #永久
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce 
Permissive
[[email protected] ~]#

2、安装docker

yum install docker 
[[email protected] ~]# systemctl enable docker  #加入开机自启动
[[email protected] ~]# systemctl start docker  #开启服务

3、下载本地私有库registry

[[email protected] ~]# docker pull registry    #默认下载最新版
[[email protected] ~]# docker images       #查看下载的镜像
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry   latest              047218491f8c        10 days ago         33.17 MB
[[email protected] ~]#

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

[[email protected] ~]#  docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry    
#默认仓库创建在/tmp/registry,用-v参数指定仓库存放位置
1e8b1a03013ee66034b40aee1820000a2ccf026a3b1e43606f3e4007b2a9d455
[[email protected] ~]#
[[email protected] ~]# docker ps   #查看运行容器
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
1e8b1a03013e        docker.io/registry   "/entrypoint.sh /etc/"   35 seconds ago      Up 32 seconds       0.0.0.0:5000->5000/tcp   goofy_mcnulty
[[email protected] ~]#

5、访问私有仓库

[[email protected] ~]# curl 127.0.0.1:5000/v2
<a href="/v2/">Moved Permanently</a>.
[[email protected] ~]#
#说明registry部署成功

6、为基础镜像打标签

[[email protected] ~]# docker search  docker.io/fedora/ssh|grep docker.io/fedora/ssh
docker.io   docker.io/fedora/ssh                                                                         20                   [OK]
[[email protected] ~]# docker pull docker.io/fedora/ssh    #下载镜像
[[email protected] ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry     latest              047218491f8c        10 days ago         33.17 MB
docker.io/fedora/ssh   latest              ad6a3ff29626        4 weeks ago         396.7 MB
[[email protected] ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh    #打标签
[[email protected] ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry     latest              047218491f8c        10 days ago         33.17 MB
127.0.0.1:5000/ssh     latest              ad6a3ff29626        4 weeks ago         396.7 MB
docker.io/fedora/ssh   latest              ad6a3ff29626        4 weeks ago         396.7 MB
[[email protected] ~]# 
[[email protected] ~]# vim /etc/sysconfig/docker
OPTIONS="--selinux-enabled  --insecure-registry 10.0.0.5:5000"    #定制私有仓库URL
[[email protected] ~]# systemctl restart docker

7、提交镜像到本地私有库

[[email protected] ~]# docker start 1e8   #开启本地库
1e8
[[email protected] ~]# docker ps 
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
1e8b1a03013e        docker.io/registry   "/entrypoint.sh /etc/"   4 hours ago         Up 3 seconds        0.0.0.0:5000->5000/tcp   goofy_mcnulty
[[email protected] ~]#
[[email protected] ~]# docker push 127.0.0.1:5000/ssh    #上传打好标签的库
The push refers to a repository [127.0.0.1:5000/ssh]
482d621bda33: Pushed 
510f15c27a8b: Pushed 
e4f86288aaf7: Pushed 
latest: digest: sha256:5ad5aec14bb7aa63fdcea1772db6ab5b5de99b0a023d234e61f5aa8c9435e8ff size: 948
[[email protected] ~]#

8、查看已经上传好的镜像

[[email protected] ~]# curl 10.0.0.5:5000/v2/_catalog
{"repositories":["ssh"]}
[[email protected] ~]#

浏览器中查看已经上传的镜像

http://10.0.0.5:5000/v2/_catalog

9、测试库是否可用,在准备好环境的另一台测试机上面下载上传的镜像

[[email protected] ~]# vim /etc/sysconfig/docker      #加入私有仓库地址
OPTIONS="--selinux-enabled  --insecure-registry 10.0.0.5:5000" 
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# docker pull 10.0.0.5:5000/ssh

可以看到已经可以下载镜像,证明私有仓库创建成功

[[email protected] ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
10.0.0.5:5000/ssh   latest              ad6a3ff29626        4 weeks ago         396.7 MB
[[email protected] ~]#

接下来通过自己的私有库运行一个centos7容器

1、从其他的数据库上save一个centos镜像推送到私有库服务器上

[[email protected] ~]# ls
anaconda-ks.cfg  centos.tar
[[email protected] ~]# docker load < centos.tar    #将镜像导入docker
34e7b85d83e4: Loading layer [==================================================>] 199.9 MB/199.9 MB
Loaded image: docker.io/centos:latest                                           ] 557.1 kB/199.9 MB
[[email protected] ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry     latest              047218491f8c        10 days ago         33.17 MB
127.0.0.1:5000/ssh     latest              ad6a3ff29626        4 weeks ago         396.7 MB
docker.io/fedora/ssh   latest              ad6a3ff29626        4 weeks ago         396.7 MB
docker.io/centos       latest              67591570dd29        12 weeks ago        191.8 MB
[[email protected] ~]#

2、再次打上自己的标签

[[email protected] ~]# docker tag docker.io/centos:latest  10.0.0.5:5000/lcentos   
 #为了区别前面的,我将centos做了其他标记
[[email protected] ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry      latest              047218491f8c        10 days ago         33.17 MB
127.0.0.1:5000/ssh      latest              ad6a3ff29626        4 weeks ago         396.7 MB
docker.io/fedora/ssh    latest              ad6a3ff29626        4 weeks ago         396.7 MB
docker.io/centos        latest              67591570dd29        12 weeks ago        191.8 MB
10.0.0.5:5000/lcentos   latest              67591570dd29        12 weeks ago        191.8 MB
[[email protected] ~]#

3、上传标记好的镜像到自己的私有库

[[email protected] ~]# docker push 10.0.0.5:5000/lcentos

4、查看上传好的镜像

[[email protected] ~]# curl http://10.0.0.5:5000/v2/_catalog

{"repositories":["lcentos","ssh"]}

[[email protected] ~]#

浏览器查看

5、再次到准备好环境的那台测试机上面pull

[[email protected] ~]# docker pull 10.0.0.5:5000/lcentos
[[email protected] ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
10.0.0.5:5000/ssh       latest              ad6a3ff29626        4 weeks ago         396.7 MB
10.0.0.5:5000/lcentos   latest              67591570dd29        12 weeks ago        191.8 MB
[[email protected] ~]#

6、创建并运行一个容器

[[email protected] ~]# docker run -d -it --privileged=false -p 80:80 --name abccentos 10.0.0.5:5000/lcentos /bin/bash
15b9f42b3d63846085664139bff0c041f614bc2b717787686d23785d98b37160
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS                NAMES
15b9f42b3d63        10.0.0.5:5000/lcentos   "/bin/bash"         16 seconds ago      Up 13 seconds       0.0.0.0:80->80/tcp   abccentos
[[email protected] ~]#

7、进入容器查看,可以看到centos的版本等信息

[[email protected] ~]# docker attach 15b9f42b3d63
[[email protected] /]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
[[email protected] /]# uname -r
3.10.0-327.el7.x86_64
[[email protected] /]# uname -a
Linux 15b9f42b3d63 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] /]#

以上就是整个创建私有镜像库的过程,欢迎一起交流学习。

时间: 2024-08-02 02:49:51

centos7.2定制属于自己的docker私有库的相关文章

建立docker私有库(docker registry)(转)

建立docker私有库(docker registry) 博客分类: docker 我的目标还是无互联网安装,部署内部的docker私有库,目前docker镜像的获得还是需要互联网,将下载好的docker镜像发布到内部私有库上(可在有互联网的时候将容器打成tar包,在离线状况下使用参照<打包docker镜像并使用文件导入>). 1.使用fedora 20(IP为192.168.1.103)作为测试服务器(centos 7,redhat 7通用) 2.安装docker Java代码   yum 

docker私有库

为了满足企业或组织内部分享镜像,官方在Github上有一个项目docker-registry, 专门用于自建Docker的私有镜像库.镜像管理是Docker的核心,为了保证镜像数据的可靠.可用和安全,docker-registry现在支持镜像数据存储在S3.GCS等云存储上. 1.registry镜像下载 首先从国内的镜像库下载registry镜像,因为国外镜像库下载太?慢了.这里我建议选择阿里的docker镜像库,在本地服务器上安装好docker后执行命令: http://blog.csdn.

docker私有库UI和添加私有库到本机能够push和pull

$ docker run -p 8080:8080 -e REG1=http://104.236.246.10:5000/v1/ atcol/docker-registry-ui$ docker run --name=registryui -p 8080:8080 -e REG1=http://0.0.0.0:5000/v1/ atcol/docker-registry-ui docker run -idt --name=Registry -e SETTINGS_FLAVOR=local -e

docker学习笔记(二)——创建私有库

本篇将介绍在docker在linux上创建私有库. 目录: 1.介绍 2.创建docker私有库 3.测试 4.参考资料 1.介绍 docker默认使用docker提供的公共库,在某些场合下,需要建立私有仓库来管理镜像.这里我们使用Docker Registry v2.0来管理docker镜像仓库. github地址:https://github.com/docker/distribution 2.创建docker私有库 启动Registry: $ docker run -d -p 5000:5

Centos7 Docker私有仓库搭建

Centos7 Docker私有仓库搭建 仓库:集中存放镜像的地方,可分为公共仓库和私有仓库(公共仓库"http://hub.docker.com"或国内的"http://www.daocloud.io") 注册服务器才是存放仓库具体的服务器(Registry),每个服务器上都可以放置多个仓库,而每个仓库上可以放置多个镜像,每个镜像上可以运行多个容器,每个容器上可以跑一个应用或应用组 原文地址:http://blog.51cto.com/13043516/21202

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.

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

docker私有仓库registry部署

准备环境:两个装有Docker(版本1.12)的虚拟机虚拟机一:192.168.2.55 用户开发机虚拟机二:192.168.2.10 用作私有仓库 搭建私有仓库 首先在10机器上下载registry镜像 $ docker pull registry 下载完之后我们通过该镜像启动一个容器 $ sudo docker run -d --restart=always -p 5000:5000 -v /export/data/docker/registry:/tmp/registry registry

手把手教你搭建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