docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > docker registry 镜像

使用Docker registry镜像创建私有仓库的方法

作者:delphiwcdj

本篇文章主要介绍了使用Docker registry镜像创建私有仓库的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

安装Docker后,可以通过官方提供的registry镜像来简单搭建一套本地私有仓库环境,本文记录简单的搭建过程。

1 使用registry启动私有仓库的容器

docker run -d -p 5000:5000 -v /root/my_registry:/tmp/registry registry

说明:若之前没有安装registry容器则会自动下载并启动一个registry容器,创建本地的私有仓库服务。默认情况下,会将仓库创建在容器的/tmp/registry目录下,可以通过 -v 参数来将镜像文件存放在本地的指定路径上(例如,放在本地目录/root/my_registry下)。

2 向私有仓库push镜像

docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04

说明:根据第一步启动的registry容器所在宿主主机的IP和Port,push某环境的本地容器。

root@gerryyang:~# docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 
The push refers to a repository [104.131.173.242:5000/ubuntu_sshd_gcc_gerry] (len: 1) 
Sending image list 
Pushing repository 104.131.173.242:5000/ubuntu_sshd_gcc_gerry (1 tags) 
511136ea3c5a: Image successfully pushed 
3b363fd9d7da: Image successfully pushed 
607c5d1cca71: Image successfully pushed 
f62feddc05dc: Image successfully pushed 
8eaa4ff06b53: Image successfully pushed 
894c0161121f: Image successfully pushed 
a45787b0222f: Image successfully pushed 
f0e3262ed661: Image successfully pushed 
Pushing tag for rev [f0e3262ed661] on {http://104.131.173.242:5000/v1/repositories/ubuntu_sshd_gcc_gerry/tags/14.04} 

宿主主机my_registry的目录结构

 root@gerryyang:~/my_registry# tree 
. 
├── images 
│  ├── 3b363fd9d7dab4db9591058a3f43e806f6fa6f7e2744b63b2df4b84eadb0685a 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── 607c5d1cca71dd3b6c04327c3903363079b72ab3e5e4289d74fb00a9ac7ec2aa 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── 894c0161121f105ac9b81bca7ac583ac1f29772625911db0fa2b6b475f5642fd 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── 8eaa4ff06b53ff7730c4d7a7e21b4426a4b46dee064ca2d5d90d757dc7ea040a 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── a45787b0222f955d68d9db34fb18033144b8a78015d9e306a1613894da0fd86e 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  ├── f0e3262ed6617896b306852c923e4c0e1d359b58b29a02ef849c4b8978c73c65 
│  │  ├── ancestry 
│  │  ├── _checksum 
│  │  ├── json 
│  │  └── layer 
│  └── f62feddc05dc67da9b725361f97d7ae72a32e355ce1585f9a60d090289120f73 
│    ├── ancestry 
│    ├── _checksum 
│    ├── json 
│    └── layer 
└── repositories 
  └── library 
    └── ubuntu_sshd_gcc_gerry 
      ├── _index_images 
      ├── tag_14.04 
      └── tag14.04_json 
 
12 directories, 35 files 

关于https的问题

root@gerryyang:~# docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 
FATA[0002] Error: Invalid registry endpoint https://104.131.173.242:5000/v1/: Get https://104.131.173.242:5000/v1/_ping: EOF. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 104.131.173.242: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/104.131.173.242:5000/ca.crt  

解决方法:

修改Docker配置文件

vim /etc/default/docker

增加以下一行

DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=104.131.173.242:5000"

重启Docker

sudo service docker restart

3 私有仓库查询方法

curl http://104.131.173.242:5000/v1/search

说明:使用curl查看仓库104.131.173.242:5000中的镜像。在结果中可以查看到ubuntu_sshd_gcc_gerry,说明已经上传成功了。

gerryyang@mba:personal_repository$curl http://104.131.173.242:5000/v1/search 
{"num_results": 0, "query": "", "results": []} 
gerryyang@mba:personal_repository$curl http://104.131.173.242:5000/v1/search 
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/ubuntu_sshd_gcc_gerry"}]} 

4 在其他的机器上访问和下载私有仓库的镜像

docker pull 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04
root@gerryyang:~# docker pull 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 
Pulling repository 104.131.173.242:5000/ubuntu_sshd_gcc_gerry 
f0e3262ed661: Download complete  
511136ea3c5a: Download complete  
3b363fd9d7da: Download complete  
607c5d1cca71: Download complete  
f62feddc05dc: Download complete  
8eaa4ff06b53: Download complete  
894c0161121f: Download complete  
a45787b0222f: Download complete  
Status: Image is up to date for 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文