Docker--建立私有仓库
- 部署私有仓库
-
- 1.拉私仓镜像
- 2.修改daemon.json配置
- 3.创建registry
- 4.启动
- 5.标记镜像
- 6.将镜像推到私仓
- 7.删除并重新下载
Docker 官方提供了一个名字 registry 当地私人仓库使用的镜像。构建内部网络 Docker 私人仓库可以快速下载和上传内网人员,不受外网带宽等因素的影响。同时,不在内网的人无法下载我们的镜像,私人仓库还支持仓库认证功能的配置。接下来详细说明 registry 建设私有仓库的过程。
部署私人仓库
1.拉私仓镜像
[root@localhost ~]# docker pull registry
2.修改daemon.json配置
[root@localhost ~]# vim /etc/docker/daemon.json
添加以下内容,让 Docker 信任私人仓库地址,保存退出。
{
"insecure-registries": ["192.168.220.101:5000"], "registry-mirrors": ["https://8eueg49g.mirror.aliyuncs.com"] }
重启
[root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart docker
3.创建registry
[root@localhost ~]# docker create -it registry /bin/bash ecdc9d451b85792d2fe9a8cb5f84cb4929669030597855c02c2a2eb04adbba76 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ecdc9d451b85 registry "/entrypoint.sh /bin…" 8 seconds ago Created lucid_einstein
4.启动
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry e42a3392761f16feca61cdc53c757174997881466532179d7cf12aa142fc4aff [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e42a3392761f registry "/entrypoint.sh /etc…" 18 seconds ago Up 17 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp priceless_banach
5.给镜像上标签
[root@localhost ~]# docker tag nginx:new 192.168.220.101:5000/nginx
6.将镜像推送至私有仓库
[root@localhost ~]# docker push 192.168.220.101:5000/nginx
Using default tag: latest
The push refers to repository [192.168.220.101:5000/nginx]
dfaa29d5d5d5: Pushed
9c4d361fbdc3: Pushed
960cc91c2969: Pushed
c92b24de3fab: Pushed
274d94e14224: Pushed
174f56854903: Pushed
latest: digest: sha256:c87d5313e852e54c816ac7780d1b27496cda38d7c47e3011eb003b75d112f68b size: 1579
7.删除并重新下载
[root@localhost ~]# docker rmi 192.168.220.101:5000/nginx:latest
Untagged: 192.168.220.101:5000/nginx:latest
Untagged: 192.168.220.101:5000/nginx@sha256:c87d5313e852e54c816ac7780d1b27496cda38d7c47e3011eb003b75d112f68b
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 06e6d37023c5 4 days ago 450MB
nginx test03 64118deb0438 5 days ago 205MB
nginx test02 7c4237800a32 5 days ago 308MB
nginx test1 bcd992cafd8a 5 days ago 310MB
nginx new 08b80aab07b0 5 days ago 539MB
registry latest b2cb11db9d3d 12 days ago 26.2MB
centos 7 8652b9f0cb4c 10 months ago 204MB
[root@localhost ~]# docker pull 192.168.220.101:5000/nginx
Using default tag: latest
latest: Pulling from nginx
Digest: sha256:c87d5313e852e54c816ac7780d1b27496cda38d7c47e3011eb003b75d112f68b
Status: Downloaded newer image for 192.168.220.101:5000/nginx:latest
192.168.220.101:5000/nginx:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 06e6d37023c5 4 days ago 450MB
nginx test03 64118deb0438 5 days ago 205MB
nginx test02 7c4237800a32 5 days ago 308MB
nginx test1 bcd992cafd8a 5 days ago 310MB
nginx new 08b80aab07b0 5 days ago 539MB
192.168.220.101:5000/nginx latest 08b80aab07b0 5 days ago 539MB
registry latest b2cb11db9d3d 12 days ago 26.2MB
centos 7 8652b9f0cb4c 10 months ago 204MB