资讯详情

【云原生丨Docker系列5】私有镜像仓库的使用方法

一、Docker Hub

注册

登录

注销

二、拉镜像

三、推镜像

四、私有仓库

五、上传、搜索、下载私人仓库的镜像

六、注意事项

Ubuntu 14.04, Debian 7 Wheezy

Ubuntu 16.04 , Debian 8 , centos 7

其它补充


一、Docker Hub

?前 Docker 官员维护公共仓库 ,?一些需求可以通过 中直接下 实现载镜像。假如你觉得拉取 如果镜像较慢,我们可以配置镜像加速 器:http://docker-cn.com/,当然,国内部分云商都提供了相应的加速器,配置简单。

注册

你可以在 https://cloud.docker.com 免费注册 Docker 账号。

登录

通过执? docker login 命令交互式输入户名和密码在命令界登录

注销

你可以通过 docker logout 退出登录。


二、拉镜像

你可以通过 docker search 命令搜索官仓库的镜像,并利 docker pull 命令将其下载到本地。 centos 搜索关键词:

$ docker search centos  NAME DESCRIPTION  STARS OFFICIAL AUTOMATED  centos The official build of CentOS.  465 [OK]  tianon/centos CentOS 5 and 6, created using rinse instea  ... 28  blalor/centos Bare-bones base CentOS 6.5 image  6 [OK]  saltstack/centos-6-minimal  6 [OK]  tutum/centos-6.4 DEPRECATED. Use tutum/centos:6.4 instead.  ... 5 [OK]

可可以看到很多返回包含镜像,包括镜像名称、描述、收藏数量(表示镜像的关注),是官员吗?创建,动态创建?。

官方镜像描述由官方项目组创建和维护,资源允许家庭验证镜像的来源和内容。

根据是否是官员提供,镜像资源可分为两类。

另外,搜索时通过 --filter=stars=N 参数可以指定,只显示收藏的数量 N 以上镜像。 centos 镜像到本地

$ docker pull centos  Pulling repository centos  0b443ba03958: Download complete  539c0211cd76: Download complete  511136ea3c5a: Download complete  7064731afe90: Download complete

三、推镜像

?户籍登录后也可以通过 docker push 命令将镜像推送到 。在下列命令中 username 请替换你的 Docker 账号户名。

$ docker tag ubuntu:17.10 username/ubuntu:17.10  $ docker image ls  REPOSITORY TAG IMAGE ID CREATED SIZE  ubuntu 17.10 275d79972a 86 6 days ago 94.6MB  username/ubuntu 17.10 275d79972a 86 6 days ago 94.6MB  $ docker push username/ubuntu:17.10  $ docker search username  NAME DESCRIPTION STARS OFFICIAL AUTOMATED  username/ubuntu

四、私有仓库

有时候使?这的公共仓库可能不⽅便,⽤户可以创建⼀个本地仓库供私⼈使⽤。

docker-registry 是官⽅提供的⼯具,可以⽤于构建私有的镜像仓库。本⽂内容基于 docker-registry v2.x 版本。你可以通过获取官⽅ registry 镜像来运⾏。

$ docker run -d -p 5000:5000 --restart=always --name registry registry

这将使⽤官⽅的 registry 镜像来启动私有仓库。默认情况下,仓库会被创建在容器的 ⽬录下。你可以通过 -v 参数来将镜像⽂件存放在本地的指定路径。例如下⾯的例⼦将上传的镜像放到本地的 ⽬录。

$ docker run -d \ 
-p 5000:5000 \ 
-v /opt/data/registry:/var/lib/registry \ 
registry

五、在私有仓库上传、搜索、下载镜像

创建好私有仓库之后,就可以使⽤ docker tag 来标记⼀个镜像,然后推送它到仓库。例如私有仓库地址为。先在本机查看已有的镜像。

$ docker image ls 
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB

使⽤ docker tag 将 ubuntu:latest 这个镜像标记为 127.0.0.1:5000/ubuntu:latest。格式为:

$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest 
$ docker image ls 
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB 
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB

 使⽤ docker push 上传标记的镜像。

$ docker push 127.0.0.1:5000/ubuntu:latest 
The push refers to repository [127.0.0.1:5000/ubuntu] 
373a30c24545: Pushed 
a9148f5200b0: Pushed 
cdd3de0940ab: Pushed
fc56279bbb33: Pushed 
b38367233d37: Pushed 
2aebd096e0e2: Pushed 
latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a si ze: 1568

⽤ curl 查看仓库中的镜像。

$ curl 127.0.0.1:5000/v2/_catalog 
{"repositories":["ubuntu"]}

这⾥可以看到,表明镜像已经被成功上传了。

先删除已有镜像,再尝试从私有仓库中下载这个镜像。

$ docker image rm 127.0.0.1:5000/ubuntu:latest 
$ docker pull 127.0.0.1:5000/ubuntu:latest 
Pulling repository 127.0.0.1:5000/ubuntu:latest 
ba5877dc9bec: Download complete 
511136ea3c5a: Download complete 
9bad880da3d2: Download complete 
25f11f5fb0cb: Download complete 
ebc34468f71d: Download complete 
2318d26665ef: Download complete 
$ docker image ls 
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB

六、注意事项

如果你不想使⽤ 作为仓库地址,⽐如想让本⽹段的其他主机也能把镜像推送到私有仓库。你就得把例如这样的内⽹地址作为私有仓库地址,这时你会发现⽆法成功推送镜像。

这是因为 Docker 默认不推送镜像。我们可以通过 来取消这个限制。

Ubuntu 14.04, Debian 7 Wheezy

对于使⽤ upstart 的系统⽽⾔,编辑 /etc/default/docker ⽂件,在其中的 DOCKER_OPTS 中增加如下内容:

DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com --insecure-registries=192.16 8.199.100:5000"

重新启动服务:

$ sudo service docker restart

Ubuntu 16.04+, Debian 8+, centos 7

对于使⽤ systemd 的系统,请在 /etc/docker/daemon.json 中写⼊如下内容(如果⽂件不存在请新建该⽂件) 

{ 
"registry-mirror": [
"https://registry.docker-cn.com" 
],
"insecure-registries": [ 
"192.168.199.100:5000"
] 
}

其它补充

对于 Docker for Windows、Docker for Mac 在设置中编辑 daemon.json 增加和上边⼀样的字符串即可。


标签: 二极管pk25f

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台