使用Docker registry镜像创建私有仓库的方法
程序员文章站
2022-06-08 09:50:17
安装docker后,可以通过官方提供的registry镜像来简单搭建一套本地私有仓库环境,本文记录简单的搭建过程。
1 使用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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。