创建和使用私有仓库
使用registry 镜像创建私有仓库
安装Docker 后,可以通过官方提供的registry 镜像来简单搭建一套本地私有仓库环境:
这将自动下载并启动一个registry 容器,创建本地的私有仓库服务。
默认情况下,会将仓库创建在容器的/tmp/registry 目录下。可以通过-v参数来将镜像文件存放在本地的指定路径上。
例如下面的例子将上传的镜像放到/opt/data/registry 目录:
此时,在本地将会启动一个私有仓库服务,监听端口为5000.
管理私有仓库镜像
在ubunt(192.168.2.126)搭建私有仓库,查看地址为192.168.2.126:5000,然后在centos(192.168.2.140)里测试上传和下载镜像。
在centos 系统查看已有镜像:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
apache centos a083e564e43a 2 weeks ago 543.6 MB
sshd2 dockerfile 52819a095193 3 weeks ago 459.7 MB
busybox buildroot-2014.02 4986bf8c1536 4 weeks ago 2.433 MB
busybox latest 4986bf8c1536 4 weeks ago 2.433 MB
centos latest 34943839435d 9 weeks ago 224 MB
使用docker tag 命令将镜像标记为192.168.2.126:5000/test
(格式为docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]):
[
root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.2.126:5000/test latest 34943839435d 9 weeks ago 224 MB
centos latest 34943839435d 9 weeks ago 224 MB
centos latest 34943839435d 9 weeks ago 224 MB
使用docker push 上传标记的镜像:
Error: Invalid registry endpoint https://192.168.2.126:5000/v1/: Get https://192.168.2.126:5000/v1/_ping: EOF. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.2.126: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/192.168.2.126:5000/ca.crt
在最新的docker 1.3.3中 无法pull ,因为默认的是https,
解决方法:
1、修改Docker配置文件
vim /etc/sysconfig/docker
增加以下一行
DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=192.168.2.126:5000"
重启Docker
sudo service docker restart
1、修改Docker配置文件
vim /etc/sysconfig/docker
增加以下一行
DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=192.168.2.126:5000"
重启Docker
sudo service docker restart
2、在客户端运行 docker 服务进程 --insecure-registry 192.168.2.126:5000
root@localhost:~# nohup docker -d --insecure-registry 192.168.2.126:5000 &
root@localhost:~# sudo docker push 192.168.2.126:5000/test
The push refers to a repository [192.168.2.126:5000/test] (len: 1)
Sending image list
Pushing repository 192.168.2.126:5000/test (1 tags)
511136ea3c5a: Image successfully pushed
53f858aaaf03: Image successfully pushed
837339b91538: Image successfully pushed
615c102e2290: Image successfully pushed
b39b81afc8ca: Image successfully pushed
Pushing tag for rev [b39b81afc8ca] on { http://192.168.2.126:5000/v1/repositories/test/tags/latest}
The push refers to a repository [192.168.2.126:5000/test] (len: 1)
Sending image list
Pushing repository 192.168.2.126:5000/test (1 tags)
511136ea3c5a: Image successfully pushed
53f858aaaf03: Image successfully pushed
837339b91538: Image successfully pushed
615c102e2290: Image successfully pushed
b39b81afc8ca: Image successfully pushed
Pushing tag for rev [b39b81afc8ca] on { http://192.168.2.126:5000/v1/repositories/test/tags/latest}
用curl 查看仓库 192.168.2.126:5000 中的镜像:
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/test"}]}
在结果中可以看到{"description": "","name":"library/test"},表明镜像已经成功上传了。
现在可以到任意一台能访问到192.168.2.126地址的机器去下载这个镜像了:
root@localhost
:/opt/data/registry# docker pull 192.168.2.126:5000/test
Pulling repository 192.168.2.126:5000/test
34943839435d: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
Status: Downloaded newer image for 192.168.2.126:5000/test:latest
root@localhost:~# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.2.126:5000/test latest b39b81afc8ca 2 weeks ago 188.3 MB
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.2.126:5000/test latest b39b81afc8ca 2 weeks ago 188.3 MB
下载后,可以添加一个更通用的标签centos
root@localhost
:~# docker tag 192.168.2.126:5000/test centos:6.5
root@localhost
:~# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos 6.5 34943839435d 9 weeks ago 224 MB