欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker 创建私有仓库

程序员文章站 2024-03-13 08:03:57
...

使用registry快速创建私有镜像仓库

Docker Registry Document

使用docker下载registry镜像

[[email protected]_32_161_centos ~]# docker pull registry:2.0
Trying to pull repository docker.io/library/registry ...
sha256:3cac1869696e4ff3435bbc30391749ac373f7471736dbb48dfa9bfde08c4efd2: Pulling from docker.io/library/registry
4d2e9ae40c41: Pull complete
a3ed95caeb02: Pull complete
7c8152785df5: Pull complete
8b04aafd7cd8: Pull complete
c97c75d2d42e: Pull complete
4b3ef98bba76: Pull complete
edee0288d356: Pull complete
ea2a9399d365: Pull complete
ddf532273b60: Pull complete
e9e91aa1843e: Pull complete
6144b0ffbb4c: Pull complete
Digest: sha256:3cac1869696e4ff3435bbc30391749ac373f7471736dbb48dfa9bfde08c4efd2
Status: Downloaded newer image for docker.io/registry:2.0

启动registry镜像

[[email protected]_32_161_centos ~]# docker run -d -p 5000:5000 registry:2.0
26ca3052d8e6561fa629b5cb0fab944c0f754410758afb72fb8d51f90f21ac72

查看镜像库

[[email protected]_32_161_centos ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis         latest              a55fbf438dfd        2 weeks ago         95 MB
docker.io/registry      2.0                 3bccd459597f        3 years ago         549 MB

镜像标记

标记一个本地镜像为私有仓库版本
此处将docker.io/redis标记为localhost:5000/redis

docker tag docker.io/redis localhost:5000/redis

推送至私有仓库

[[email protected]_32_161_centos ~]# docker push localhost:5000/redis
The push refers to a repository [localhost:5000/redis]
f02e80b7746e: Pushed
290c0f1ac500: Pushed
f3918e45d85b: Pushed
1540700d9a4f: Pushed
b52995330c04: Pushed
5dacd731af1b: Pushed
latest: digest: sha256:5f1b1b3af977e31cf9ce7d63c7c95372e05ef27af0ea1341fcce734a161c2e70 size: 11037

从私有仓库拉取镜像

拉取本地私有仓库镜像

docker pull localhost:5000/redis

拉取远程私有仓库镜像

这里选择另外一台装有docker的服务器
首先更改配置文件/etc/docker/daemon.json

{ "insecure-registries":["xxx.xxx.xxx.xxx:5000"] }

xxx.xxx.xxx.xxx替换为远程私有仓库ip

重启docker

systemctl restart docker

拉取镜像

[[email protected]_32_15_centos ~]# docker pull xxx.xxx.xxx.xxx:5000/redis
Using default tag: latest
Trying to pull repository xxx.xxx.xxx.xxx:5000/redis ...
sha256:5f1b1b3af977e31cf9ce7d63c7c95372e05ef27af0ea1341fcce734a161c2e70: Pulling from xxx.xxx.xxx.xxx:5000/redis
27833a3ba0a5: Pull complete
cde8019a4b43: Pull complete
97a473b37fb2: Pull complete
c6fe0dfbb7e3: Pull complete
39c8f5ba1240: Pull complete
cfbdd870cf75: Pull complete
Digest: sha256:5f1b1b3af977e31cf9ce7d63c7c95372e05ef27af0ea1341fcce734a161c2e70
Status: Downloaded newer image for xxx.xxx.xxx.xxx:5000/redis:latest

至此,就成功创建私有仓库上传了第一个镜像,并完成了下载

相关标签: Docker 私有仓库