创建Docker私有仓库

概念

Docker 包括三个基本概念

  1. 镜像(Image)
  2. 容器(Container)
  3. 仓库(Repository)
    理解了这三个概念,就理解了 Docker 的整个生命周期。
镜像

镜像是只读的。
镜像可以想象成操作系统的安装镜像(例如CentOS6.8.ISO)。

容器

容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全的平台。
可以理解成 我们通过镜像安装操作系统,我们可以开机,关机,等操作。

仓库

仓库是集中存放镜像文件的场所。
有时候会把仓库和仓库注册服务器(Registry)混为一谈,并不严格区分。
实际上,仓库注册服务器上往往存放着多个仓库。
每个仓库中又包含了多个镜像,每个镜像有不同的标签(tag)。

一个仓库中可能有centos ubuntu fedora等镜像,然后ubuntu可以有12 13 15 16等版本则使用标签标明。

仓库分为公开仓库(Public)和私有仓库(Private)两种形式。

Registry部署私有仓库

官方提供了 registry 镜像来启动本地的私有仓库。

docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always registry:2.5.0

不指定tag时候镜像一直下载失败,
https://hub.docker.com/r/library/registry/tags/ 找到tag
默认时候仓库数据存在的位置是/var/lib/registry 可以通过参数v改变仓库数据的位置。

查看容器运行情况

[root@bogon docker]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
2119ae9bc14d        registry:2.5.0      "/entrypoint.sh /etc   17 minutes ago      Up 17 minutes       0.0.0.0:5000->5000/tcp   sharp_sinoussi

说明docker的私有仓库已经运行成功,打开浏览器访问显示如下内容说明运行正常。
429440-20160806170315325-1593893783.png

验证

打开另一台机器
然后推送一个镜像到registry中

[root@bogon opt]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              6.8                 c51f770ba2ca        5 weeks ago         194.5 MB
[root@bogon opt]# docker tag c51f770ba2ca 192.168.1.106:5000/centos:6.8
[root@bogon opt]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos                 6.8                 c51f770ba2ca        5 weeks ago         194.5 MB
192.168.1.106:5000/centos   6.8                 c51f770ba2ca        5 weeks ago         194.5 MB

[root@bogon opt]# docker push 192.168.1.106:5000/centos
The push refers to a repository [192.168.1.106:5000/centos] (len: 1)
c51f770ba2ca: Image already exists 
c51f770ba2ca: Buffering to Disk 
b92e3b877355: Image successfully pushed 
b92e3b877355: Buffering to Disk 
Digest: sha256:bb00aaaf4f7993e3d34b02c58573622c4c039712611f521313a7fd00ba687571
可能的问题提示https什么的

需要在客户端机的docker配置文件上添加other_args="--insecure-registry 192.168.1.106:5000"

echo 'other_args="--insecure-registry 192.168.1.106:5000"' >> /etc/sysconfig/docker

centos7下使用

/etc/sysconfig/docker
OPTIONS='--selinux-enabled=false --log-driver=journald --insecure-registry 192.168.1.106:5000'

显示push完成 然后通过浏览器访问Registry服务器。如下图
429440-20160806183158293-1956015264.png

我们可以删除新开的机器上面刚push的镜像,然后在pull下来验证一下

[root@bogon opt]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos                      6.8                 c51f770ba2ca        5 weeks ago         194.5 MB
192.168.1.106:5000/centos   6.8                 c51f770ba2ca        5 weeks ago         194.5 MB
[root@bogon opt]# docker rmi -f c51f770ba2ca
Untagged: 192.168.1.106:5000/centos:6.8
Untagged: centos:6.8
Deleted: c51f770ba2ca4650038d1a058e13d42195cf481151da1287341a9d44903094c9
Deleted: 7392cee6d21bde3366cffc70d2404e184e8aeac95b2e9198afea920411e0cb00
Deleted: b92e3b87735596ebdc9d0f9b9254ebabc8101513b14e9ebbb924bbddd32a1df5
Deleted: 3690474eb5b4b26fdfbd89c6e159e8cc376ca76ef48032a30fa6aafd56337880
[root@bogon opt]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
[root@bogon opt]# docker pull 192.168.1.106:5000/centos:6.8
6.8: Pulling from 192.168.1.106:5000/centos
3690474eb5b4: Pull complete 
b92e3b877355: Pull complete 
7392cee6d21b: Pull complete 
c51f770ba2ca: Already exists 
Digest: sha256:bb00aaaf4f7993e3d34b02c58573622c4c039712611f521313a7fd00ba687571
Status: Downloaded newer image for 192.168.1.106:5000/centos:6.8
[root@bogon opt]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
192.168.1.106:5000/centos   6.8                 c51f770ba2ca        5 weeks ago         194.5 MB

然后运行这个容器从root@bogon变成了root@288ff131f83a说明运行也没问题。

[root@bogon opt]# docker run -it 192.168.1.106:5000/centos:6.8 "bin/bash"
[root@288ff131f83a /]# hostname 
288ff131f83a

转载于:https://www.cnblogs.com/baolong/p/5743748.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值