本文主要内容是使用Docker Registry的使用方法。
Docker Registry使用
相关文章
本文主要内容是使用Docker Registry的使用方法,如果要看编译方法,请看以下文章。
运行环境
- centos 7.2+
Docker Registry源安装
部署说明
说明:准备两台服务器,一台服务端搭建Docker Registry,负责储存docker镜像;另一台进行测试。
安装docker-registry(服务端)
yum -y install docker-registry
查看安装后docker-distribution的的配置文件位置(服务端)
rpm -ql docker-distribution
/etc/docker-distribution/registry/config.yml
/usr/bin/registry
/usr/lib/systemd/system/docker-distribution.service
/usr/share/doc/docker-distribution-2.6.2
/usr/share/doc/docker-distribution-2.6.2/AUTHORS
/usr/share/doc/docker-distribution-2.6.2/CONTRIBUTING.md
/usr/share/doc/docker-distribution-2.6.2/LICENSE
/usr/share/doc/docker-distribution-2.6.2/MAINTAINERS
/usr/share/doc/docker-distribution-2.6.2/README.md
/var/lib/registry #数据放在这个目录下,可以修改/etc/docker-distribution/registry/config.yml改这个路径
查看配置文件(服务端)
cat /etc/docker-distribution/registry/config.yml
version: 0.1
log:
fields:
service: registry
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /var/lib/registry #镜像存储位置,可以修改成自己的
http:
addr: :5000 #监听端口为5000
启动服务(服务端)
systemctl start docker-distribution
systemctl enable docker-distribution
Created symlink from /etc/systemd/system/multi-user.target.wants/docker-distribution.service to /usr/lib/systemd/system/docker-distribution.service.
至此,Docker Registry镜像源安装完毕,想要看使用方法请继续往下看
Docker Registry测试
把另一台机器上的镜像推到docker-registry机器上。(客户端)
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.16.80.99:5000/mysql 5.7.22 64f5d945efcc 2 weeks ago 1.2 MB
docker.io/busybox latest 64f5d945efcc 2 weeks ago 1.2 MB
172.16.80.253:5000/busybox v1 64f5d945efcc 2 weeks ago 1.2 MB
172.16.80.99:5000/docker.io/busybox latest 64f5d945efcc 2 weeks ago 1.2 MB
其中,mydocker.io为主机名,需更改客户端hosts文件
下面进行打标签(客户端)
docker tag 172.16.80.99:5000/docker.io/busybox:latest mydocker.io:5000/busybox:5.7.22
docker push mydocker.io:5000/busybox
推镜像(客户端)
[root@localhost ~]# docker push mydocker.io:5000/busybox:5.7.22
The push refers to a repository [mydocker.io:5000/busybox]
d1156b98822d: Pushed
5.7.22: digest: sha256:4fe8827f51a5e11bb83afa8227cbccb402df840d32c6b633b7ad079bc8144100 size: 527
查看进行文件(客户端)
[root@localhost certs]# ll /var/lib/registry/docker/registry/v2/repositories/
busybox/ docker.io/
[root@localhost certs]# ll /var/lib/registry/docker/registry/v2/repositories/busybox/
总用量 0
drwxr-xr-x. 3 root root 20 5月 27 12:04 _layers
drwxr-xr-x. 4 root root 35 5月 27 12:04 _manifests
drwxr-xr-x. 2 root root 6 5月 27 12:04 _uploads
docker pull测试(客户端)
[root@localhost ~]# docker pull mydocker.io:5000/busybox:5.7.22
Trying to pull repository mydocker.io:5000/busybox ...
5.7.22: Pulling from mydocker.io:5000/busybox
Digest: sha256:4fe8827f51a5e11bb83afa8227cbccb402df840d32c6b633b7ad079bc8144100
Status: Downloaded newer image for mydocker.io:5000/busybox:5.7.22
至此,容器镜像仓库搭建完成,如果有错,请参考下面的解决方法。
报错总结
问题总结(没报错请忽略):
错误1(客户端更改)
Get https://mydocker.io:5000/v1/_ping: http: server gave HTTP response to HTTPS client错误
解决方法
- 说明:
- push 时报错了,这是因为docker 客户端默认使用的https形式的,但是dockr registry server端是http形式的。
- 解决方法:
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["docker-registry:5000"]
}
systemctl restart docker
错误2(检查服务端)
Put http://mydocker.io:5000/v1/repositories/busybox/: dial tcp 172.16.80.99:5000: getsockopt: no route to host错误
解决方法
网络不通 方法:请检查docker-registry防火墙