Docker仓库管理

1、# docker pull registry //下载registry镜像,registry为docker官方提供的一个镜像,我们可以用它来创建本地的docker私有仓库。

2、# docker run -d -p 5000:5000 registry //以registry镜像启动容器,监听5000端口

    # docker exec -it a9f bash //宿主机和容器同时监听了5000端口

3、# curl 127.0.0.1:5000 //可以访问它

   访问结果:"\"docker-registry server\""

4、把镜像上传到私有仓库:

先下载一个busybox(很小,方便测试)的镜像

# docker pull busybox

# docker tag busybox 10.10.10.201:5000/busybox //标记一下tag,必须要带有私有仓库的ip:port

上传镜像到私有仓库:

# docker push 10.10.10.201:5000/busybox

会有如下错误提示(如果IP地址写的不是本地ip也会有错):

Error response from daemon: invalid registry endpoint "http://10.10.10.201:5000/v0/". HTTPS attempt: unable to ping registry endpoint https://10.10.10.201:5000/v0/

v2 ping attempt failed with error: Get https://10.10.10.201:5000/v2/: dial tcp 10.10.10.201:5000: connection refused

 v1 ping attempt failed with error: Get https://10.10.10.201:5000/v1/_ping: dial tcp 10.10.10.201:5000: connection refused. HTTP attempt: unable to ping registry endpoint http://10.10.10.201:5000/v0/

v2 ping attempt failed with error: Get http://10.10.10.201:5000/v2/: dial tcp 10.10.10.201:5000: connection refused

 v1 ping attempt failed with error: Get http://10.10.10.201:5000/v1/_ping: dial tcp 10.10.10.201:5000: connection refused

这是因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互式就会有上面的错误,为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问,解决方法为

# vim /etc/init.d/docker

把$exec -d $other_args改为$exec -d --insecure-registry 10.10.10.201:5000 $other_args

重启docker服务

# /etc/init.d/docker restart

启动容器:

# docker start registry_container_id

查看私有仓库里的所有镜像

# curl http://10.10.10.201:5000/v1/search

posted @ 2016-05-26 13:36  fansik  阅读(589)  评论(0编辑  收藏  举报