一、私有库配置
有时候使用Docker Hub这样的公共仓库可能不方便(有时候无法访问),用户可以创建一个本地仓库供私人使用,这里介绍如何配置使用本地仓库。网络上配置docker私有仓库的方法不少,有借助Docker Hub的,也有直接使用别人创建好的私有仓库的,这里简单介绍使用官方提供的工具docker-registry来配置私有库
服务器:centos7.x x86_64 IP:10.0.90.25 docker版本:Docker version 1.12.0, build 8eab29e
1、使用官方提供的工具来配置
docker-registry 是官方提供的工具,可以用于构建私有的镜像仓库。
1 2 3 4 5 6 7 | 首先查看原有的镜像 #docker images REPOSITORY TAG IMAGE ID CREATED SIZE web new dcca36f7ba99 7 days ago 269.2 MB testweb new 890b0964f807 7 days ago 194.6 MB centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB centos latest 970633036444 3 weeks ago 196.7 MB |
2、然后获取官方 registry 镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #docker pull registry Using default tag: latest latest: Pulling from library /registry e110a4a17941: Pull complete 2ee5ed28ffa7: Pull complete d1562c23a8aa: Pull complete 06ba8e23299f: Pull complete 802d2a9c64e8: Pull complete Digest: sha256:1b68f0d54837c356e353efb04472bc0c9a60ae1c8178c9ce076b01d2930bcc5d Status: Downloaded newer image for registry:latest 查看是否pull成功 # docker images REPOSITORY TAG IMAGE ID CREATED SIZE web new dcca36f7ba99 7 days ago 269.2 MB testweb new 890b0964f807 7 days ago 194.6 MB centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB centos latest 970633036444 3 weeks ago 196.7 MB registry latest c6c14b3960bd 3 weeks ago 33.28 MB #表示已经成功了 |
3、基于私有仓库镜像运行容器
1 2 3 4 5 6 7 8 | #docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry a08a501701eba97c8f56fbc9b63e6f356dec1283b6c07f0f931639b4514b3838 查看运行的容器 #docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0d79735868cd centos "/bin/bash" Less than a second ago Exited (137) Less than a second ago centos7 43b66a52f166 centos:centos6 "/bin/bash" Less than a second ago Exited (137) Less than a second ago server1 a08a501701eb registry "/entrypoint.sh /etc/" 3 seconds ago Up 3 seconds 0.0.0.0:5000->5000 /tcp high_bardeen #已经运行了 |
PS:这里说明一下,默认情况下,仓库会被创建在容器的/tmp/registry目录下,但是可以通过-v参数来将镜像文件存放在本地的指定路径。
例如上面的例子是将上传的镜像放到/opt/data/registry 目录
#docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
访问私有仓库:
1 2 3 4 | #curl 127.0.0.1:5000/v1/search #不知道什么原因,我测试的时候使用curl提示404 404 page not found #curl 127.0.0.1:5000/v1/search #网上有一个例子,提示如下信息; { "num_results" : 0, "query" : "" , "results" : []} // 私有仓库为空,没有提交新镜像到仓库中 |
4、创建镜像链接或为基础镜像打个标签
1 2 3 4 5 6 7 8 9 | #docker tag registry 127.0.0.1:5000/ssh #这里选择为registry镜像打标签 [root@docker ~] # docker images REPOSITORY TAG IMAGE ID CREATED SIZE web new dcca36f7ba99 7 days ago 269.2 MB testweb new 890b0964f807 7 days ago 194.6 MB centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB centos latest 970633036444 3 weeks ago 196.7 MB 127.0.0.1:5000 /ssh latest c6c14b3960bd 3 weeks ago 33.28 MB registry latest c6c14b3960bd 3 weeks ago 33.28 MB |
5、提交镜像到本地私有仓库中
1 2 3 4 5 6 7 8 9 10 11 | #docker push 127.0.0.1:5000/ssh The push refers to a repository [127.0.0.1:5000 /ssh ] 3bb5bc5ad373: Pushed 35039a507f7a: Pushed d00444e19d65: Pushed aa3a31ee27f3: Pushed 4fe15f8d0ae6: Pushed latest: digest: sha256:51d8869caea35f58dd6a2309423ec5382f19c4e649b5d2c0e3898493f42289d6 size: 1363 注意:没报错,应该push成功了!查看私有仓库是否存在对应的镜像,依然提示404 #curl 127.0.0.1:5000/v1/search 404 page not found |
更多内容
http://blog.51cto.com/linuxg/1842588
你打算打赏多少钱呢?
(微信扫一扫)