Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1795204
  • 博文数量: 286
  • 博客积分: 3713
  • 博客等级: 少校
  • 技术积分: 2275
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-11 09:47
个人简介

http://blog.chinaunix.net/uid/16979052.html

文章分类

全部博文(286)

文章存档

2018年(1)

2017年(16)

2016年(9)

2015年(17)

2014年(15)

2013年(112)

2012年(116)

分类: 云计算

2015-08-07 09:10:11

原文地址:制作自己的Docker Registry 作者:frankzfz

1. 相关的版本信息
 
这里使用的docker的版本为1.0.1,这里使用的Ubuntu14.04 

点击(此处)折叠或打开

  1. ubuntu@10-10-68-54:~$ sudo docker info
  2. [sudo] password for ubuntu:
  3. Containers: 1
  4. Images: 78
  5. Storage Driver: aufs
  6.  Root Dir: /var/lib/docker/aufs
  7.  Dirs: 80
  8. Execution Driver: native-0.2
  9. Kernel Version: 3.13.0-24-generic
  10. WARNING: No swap limit support
  11. ubuntu@10-10-68-54:~$ sudo docker version
  12. Client version: 1.0.1
  13. Client API version: 1.12
  14. Go version (client): go1.2.1
  15. Git commit (client): 990021a
  16. Server version: 1.0.1
  17. Server API version: 1.12
  18. Go version (server): go1.2.1
  19. Git commit (server): 990021a
  20. ubuntu@10-10-68-54:~$ sudo docker --version
  21. Docker version 1.0.1, build 990021a
 2. 安装Registry
  Docker官方有免费的public pub,也有付费的private pub,我们也可以使用官方提供的docker registry在本地搭建自己的私有仓库,这样就可以再局域网中push/pull镜像了,可以很方便的进行push/pull操作,并且速度很快。这一节就是介绍registry的相关信息,这里使用的docker的版本为1.0.1,和最新版本的docker可能有所不同,主要体现在安全方面。

点击(此处)折叠或打开

  1. ubuntu@10-10-68-54:~$ sudo docker run -d -p 5000:5000 registry
  2. Unable to find image 'registry' locally
  3. Pulling repository registry
  4. e33e81d7024c: Download complete
  5. e33e81d7024c: Pulling image (latest) from registry
  6. 511136ea3c5a: Download complete
  7. f3c84ac3a053: Download complete
  8. a1a958a24818: Download complete
  9. 9fec74352904: Download complete
  10. 6cfde7386ab2: Download complete
  11. 18338e557800: Download complete
  12. 4e369c8d4164: Download complete
  13. 0c2bd7250cff: Download complete
  14. d19d6b16e220: Download complete
  15. 89b39fe82d93: Download complete
  16. 881764bc7f3a: Download complete
  17. 6173f4c32b49: Download complete
  18. 14cf53930f50: Download complete
  19. 5573b22f32578152556c356548a79dc6bd1db63c2bdc4c24a0d9f9b3efba2fd0
使用docker images命令查看

点击(此处)折叠或打开

  1. ubuntu@10-10-68-54:~$ sudo docker images
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. registry latest e33e81d7024c 7 days ago 413.7 MB
  4. ubuntu latest d0955f21bf24 8 days ago 188.3 MB
  5. ubuntu 14.04 d0955f21bf24 8 days ago
使用docker ps命令查看,可以看到运行的容器

  也可以使用下面的命令指定镜像存在的位置,
sudo docker run -d -p 5000:5000 -v /data:/tmp/registry registry
  在另一台PC上push到registry服务器后,可以在相应的目录下查看到下面的三个目录,push的镜像在images,repositories
 使用docker tag对其进行改名

点击(此处)折叠或打开

  1. ubuntu@10-10-68-54:~$ sudo docker tag d0955f21bf24 10.10.68.54:5000/ubuntu
  2. ubuntu@10-10-68-54:~$ sudo docker images
  3. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  4. registry latest e33e81d7024c 7 days ago 413.7 MB
  5. ubuntu latest d0955f21bf24 8 days ago
  6. 10.10.68.54:5000/ubuntu latest d0955f21bf24 8 days ago
然后使用docker push把该镜像push到刚刚创建的registry 服务器上。

点击(此处)折叠或打开

  1. ubuntu@10-10-68-54:~$ sudo docker push 10.10.68.54:5000/ubuntu
  2. The push refers to a repository [10.10.68.54:5000/ubuntu] (len: 1)
  3. Sending image list
  4. Pushing repository 10.10.68.54:5000/ubuntu (1 tags)
  5. 511136ea3c5a: Image successfully pushed
  6. f3c84ac3a053: Image successfully pushed
  7. a1a958a24818: Image successfully pushed
  8. 9fec74352904: Image successfully pushed
  9. d0955f21bf24: Image successfully pushed
  10. Pushing tag for rev [d0955f21bf24] on {http://10.10.68.54:5000/v1/repositories/ubuntu/tags/latest}
在另一台PC上可以使用下面的命令进行pull,

点击(此处)折叠或打开

  1. ubuntu@10-10-78-18:~$ sudo docker pull 10.10.68.54:5000/ubuntu
  2. Pulling repository 10.10.68.54:5000/ubuntu
  3. d0955f21bf24: Download complete
  4. 511136ea3c5a: Download complete
  5. f3c84ac3a053: Download complete
  6. a1a958a24818: Download complete
  7. 9fec74352904: Download complete
通过docker images可以看到,可以从刚才创建的registry上pull镜像到另一个PC上。

点击(此处)折叠或打开

  1. ubuntu@10-10-78-18:~$ sudo docker images
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. 10.10.68.54:5000/ubuntu latest d0955f21bf24 8 days ago 192.7 MB
我们能从registry上pull一个镜像,也可以从另一台PC上push一个镜像到registry上,先从docker.cn上pull一个centos6.3-base的镜像,

点击(此处)折叠或打开

  1. ubuntu@10-10-78-18:~$ sudo docker pull frankzfz/centos6.3-base
  2. [sudo] password for ubuntu:
  3. Pulling repository frankzfz/centos6.3-base
  4. a8fe6b2d8f23: Download complete
然后使用下面的命令push到registy上,
ubuntu@10-10-78-18:~$ sudo docker images
REPOSITORY          TAG       IMAGE ID          CREATED           VIRTUAL SIZE
10.10.68.54:5000/ubuntu   latest     d0955f21bf24        8 days ago          192.7 MB
frankzfz/centos6.3-base   latest       a8fe6b2d8f23        3 weeks ago         738 MB
但是直接使用下面的命令并不能push成功,
ubuntu@10-10-78-18:~$ sudo docker push 10.10.68.54:5000/frankzfz/centos6.3-base
The push refers to a repository [10.10.68.54:5000/frankzfz/centos6.3-base] (len: 0)
2015/03/28 20:38:21 No such id: 10.10.68.54:5000/frankzfz/centos6.3-base
使用docker tag 对刚才的进行镜像进行改名。
ubuntu@10-10-78-18:~$ sudo docker tag a8fe6b2d8f23 10.10.68.54:5000/centos6.3-base
ubuntu@10-10-78-18:~$ sudo docker images
REPOSITORY          TAG       IMAGE ID            CREATED         VIRTUAL SIZE
10.10.68.54:5000/ubuntu   latest    d0955f21bf24        8 days ago          192.7 MB
frankzfz/centos6.3-base  latest        a8fe6b2d8f23        3 weeks ago         738 MB
10.10.68.54:5000/centos6.3-base   latest a8fe6b2d8f23      3 weeks ago         738 MB
Push到刚才建立registy的机器上。
ubuntu@10-10-78-18:~$ sudo docker push 10.10.68.54:5000/centos6.3-base
The push refers to a repository [10.10.68.54:5000/centos6.3-base] (len: 1)
Sending image list
Pushing repository 10.10.68.54:5000/centos6.3-base (1 tags)
a8fe6b2d8f23: Image successfully pushed
Pushing tag for rev [a8fe6b2d8f23] on {}
3 测试验证
现在把创建的centos6.3-base删除掉,然后使用pull命令从registry进行拉取。
ubuntu@10-10-78-18:~$ sudo docker images
REPOSITORY     TAG            IMAGE ID        CREATED          VIRTUAL SIZE
10.10.68.54:5000/ubuntu   latest     d0955f21bf24     8 days ago          192.7 MB
通过上面的信息可以看出已经把刚才centos-6.3的images给删除了,然后通过下面的命令从10.10.68.54上进行拉取。
ubuntu@10-10-78-18:~$ sudo docker pull  10.10.68.54:5000/centos6.3-base
Pulling repository 10.10.68.54:5000/centos6.3-base
a8fe6b2d8f23: Download complete
image (latest) from 10.10.68.54:5000/centos6.3-base
ubuntu@10-10-78-18:~$ sudo docker images
REPOSITORY      TAG            IMAGE ID         CREATED           VIRTUAL SIZE
10.10.68.54:5000/ubuntu     latest     d0955f21bf24     8 days ago          192.7 MB
10.10.68.54:5000/centos6.3-base   latest   a8fe6b2d8f23        3 weeks ago     738 MB
在registry的服务器上可以看到刚才push的镜像目录。


4 新版本Docker配置
对于docker1.3.x的版本增加了安全性,docker registry交互默认使用的是https,上面搭建的私有仓库只提供http服务,所以如果在docker1.3.X以后的版本使用上面的搭建私有仓库的方式,会出现下面的错误信息:
Error: Invalid registry endpoint ... Get ... If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add '--insecure-registry 10.10.63.106:5000' to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/10.10.63.106:5000/ca.crt  
解决方法在etc/sysconfig/docker文件中添加--insecure-registry=10.10.63.106:5000,
cat  /etc/sysconfig/docker
# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS=--selinux-enabled -H fd://
DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=10.10.63.106:5000"

# Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp
或者修改/usr/lib/systemd/system/docker.service,在该文件中修改下面的一行。
[root@10-10-63-106 ~]# cat /usr/lib/systemd/system/docker.service.back
[Unit]
Description=Docker Application Container Engine
Documentation= /> After=network.target docker.socket
Requires=docker.socket

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
ExecStart=/usr/bin/docker -d --insecure-registry 10.10.63.106:5000 $OPTIONS $DOCKER_STORAGE_OPTIONS
LimitNOFILE=1048576
LimitNPROC=1048576
MountFlags=private

[Install]
WantedBy=multi-user.target
在启动registry容器的时候,使用下面的命令,
docker run  -p 5000:5000 registry
出现下面的容器信息,使用netstat –nlp可以查看到监听的端口号为5000.

在指定目录下生成下面的两个子目录:

参考文献:

http://alexander.holbreich.org/2014/07/moving-docker-images-different-partition/

https://github.com/docker/docker/tree/master/daemon/graphdriver/devmapper

管理员在2009年8月13日编辑了该文章文章。

-->
阅读(1144) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~