欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > 五、Docker本地镜像发布到私有库

五、Docker本地镜像发布到私有库

2025/5/3 3:53:08 来源:https://blog.csdn.net/weixin_42171272/article/details/140154724  浏览:    关键词:五、Docker本地镜像发布到私有库

目录

1、下载镜像Docker Registry

2、运行私有库Registry,相当于本地有个私有的Docker hub

3、演示创建一个新镜像,Ubuntu安装ifconfig命令

4、curl验证私服库上有什么镜像

5、将新镜像修改符合私服规范的tag

6、修改配置文件使之支持http

7、push推送到私服库

8、curl验证私服库上有什么镜像

9、pull到本地运行


1、下载镜像Docker Registry

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete 
0d96da54f60b: Pull complete 
5b27040df4a2: Pull complete 
e2ead8259a04: Pull complete 
3790aef225b9: Pull complete 
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localhost ~]# 
[root@localhost ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED        SIZE
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago   177MB
registry                                                   latest    b8604a3fe854   2 years ago    26.2MB

2、运行私有库Registry,相当于本地有个私有的Docker hub

命令:
-v 宿主机的路径:容器内的路径
[root@localhost usr]# docker run -d -p 5000:5000 -v /usr/myregistry/:/tmp/registry --privileged=true registry
017625b728228dffc240388e0728a969e20be0f0ebf098cc5b8ccc1af4de55bb
[root@localhost usr]# 
[root@localhost usr]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
017625b72822   registry   "/entrypoint.sh /etc…"   6 seconds ago   Up 5 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   boring_hopper
[root@localhost usr]# 

3、演示创建一个新镜像,Ubuntu安装ifconfig命令

启动一个镜像,这个ubuntu,是不具备vim命令的,最初的那个镜像
[root@localhost usr]# docker run -it ubuntu /bin/bash
root@2b0c6f8d15f0:/# vim a.txt
bash: vim: command not found
root@2b0c6f8d15f0:/# 
root@2b0c6f8d15f0:/# ifconfig
bash: ifconfig: command not found
root@2b0c6f8d15f0:/# 
#安装ifconfig
root@2b0c6f8d15f0:/# apt-get update 
root@2b0c6f8d15f0:/# apt-get install net-tools
root@2b0c6f8d15f0:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)RX packets 8475  bytes 32375039 (32.3 MB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 7578  bytes 414607 (414.6 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@2b0c6f8d15f0:/# 
#commit 成自己的私有镜像
Ctrl+p+q退出
[root@localhost usr]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
2b0c6f8d15f0   ubuntu     "/bin/bash"              6 minutes ago   Up 6 minutes                                               eager_wright
017625b72822   registry   "/entrypoint.sh /etc…"   8 minutes ago   Up 8 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   boring_hopper
[root@localhost usr]# 
[root@localhost usr]# docker commit -m="add ifconfig cmd" -a="wu" 2b0c6f8d15f0 wuubuntu:1.2
sha256:21423a381c8c6769e410a20d3cf11d773c1caad29ea1c1ecadb7c6c197033e88
[root@localhost usr]# 
[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
wuubuntu                                                   1.2       21423a381c8c   4 seconds ago   126MB#停止原始的镜像
[root@localhost usr]# docker stop 2b0c6f8d15f0
2b0c6f8d15f0
#启动新镜像
[root@localhost usr]# docker run -it 21423a381c8c /bin/bash
root@adc1c0b57a68:/# 
root@adc1c0b57a68:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)RX packets 6  bytes 508 (508.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@adc1c0b57a68:/# 

4、curl验证私服库上有什么镜像

现在有一个新的镜像,有一个私有库在运行,我们要把这个镜像推送到私有库
[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
wuubuntu                                                   1.2       21423a381c8c   4 minutes ago   126MB
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago    177MB
wu/ubuntu                                                  latest    9fd000d64b52   2 days ago      72.8MB
redis                                                      latest    7614ae9453d1   2 years ago     113MB
registry                                                   latest    b8604a3fe854   2 years ago     26.2MB
ubuntu                                                     latest    ba6acccedd29   2 years ago     72.8MB
hello-world                                                latest    feb5d9fea6a5   2 years ago     13.3kB
[root@localhost usr]# 
先验证私有库是否有其他镜像
[root@localhost usr]# curl -XGET http://192.168.153.128:5000/v2/_catalog
{"repositories":[]}  #为空,表示没有
[root@localhost usr]# 

5、将新镜像修改符合私服规范的tag

公式:
docker tag 镜像:Tag Host:port/Repository:Tag使用命令 docker tag 将wuubuntu:1.2这个镜像修改为192.168.153.128:5000/wuubuntu:1.2
[root@localhost usr]# docker tag wuubuntu:1.2 192.168.153.128:5000/wuubuntu:1.2
[root@localhost usr]# 
[root@localhost usr]# docker images
REPOSITORY                                      TAG       IMAGE ID       CREATED          SIZE
192.168.153.128:5000/wuubuntu                   1.2       21423a381c8c   13 minutes ago   126MB
wuubuntu                                        1.2       21423a381c8c   13 minutes ago   126MB#可以看到已经成功了,wuubuntu 为本地的镜像,192.168.153.128:5000/wuubuntu为传到私服库的镜像,所以需要按照私服库的规范来。

6、修改配置文件使之支持http

由于docker 有安全加固,默认是不支持http方式推送镜像的,所以需要做一个配置,取消限制
[root@localhost usr]# cat /etc/docker/daemon.json 
{"registry-mirrors": ["https://t2exmlj4.mirror.aliyuncs.com"],"insecure-registries": ["192.168.153.128:5000"]
}
[root@localhost usr]# 
添加:"insecure-registries": ["192.168.153.128:5000"]
注意:这是JSON格式,两个配置中间有逗号
修改完如果不生效,建议重启docker

7、push推送到私服库

[root@localhost usr]# docker push 192.168.153.128:5000/wuubuntu:1.2
The push refers to repository [192.168.153.128:5000/wuubuntu]
a7d9a2b2f1ad: Pushed 
9f54eef41275: Pushed 
1.2: digest: sha256:e248a868f5367e4416b1e609bf46b2d01a241758488d6abc467cc0dfeb782a48 size: 741
[root@localhost usr]# 

8、curl验证私服库上有什么镜像

[root@localhost usr]# curl -XGET http://192.168.153.128:5000/v2/_catalog
{"repositories":["wuubuntu"]}
[root@localhost usr]# 

9、pull到本地运行

[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED          SIZE
192.168.153.128:5000/wuubuntu                              1.2       21423a381c8c   25 minutes ago   126MB
wuubuntu                                                   1.2       21423a381c8c   25 minutes ago   126MB
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago     177MB
wu/ubuntu                                                  latest    9fd000d64b52   2 days ago       72.8MB
redis                                                      latest    7614ae9453d1   2 years ago      113MB
registry                                                   latest    b8604a3fe854   2 years ago      26.2MB
ubuntu                                                     latest    ba6acccedd29   2 years ago      72.8MB[root@localhost usr]# 
[root@localhost usr]# docker rmi -f 192.168.153.128:5000/wuubuntu:1.2
Untagged: 192.168.153.128:5000/wuubuntu:1.2
Untagged: 192.168.153.128:5000/wuubuntu@sha256:e248a868f5367e4416b1e609bf46b2d01a241758488d6abc467cc0dfeb782a48
[root@localhost usr]# 
[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED          SIZE
wuubuntu                                                   1.2       21423a381c8c   26 minutes ago   126MB
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago     177MB
wu/ubuntu                                                  latest    9fd000d64b52   2 days ago       72.8MB
redis                                                      latest    7614ae9453d1   2 years ago      113MB
registry                                                   latest    b8604a3fe854   2 years ago      26.2MB
ubuntu                                                     latest    ba6acccedd29   2 years ago      72.8MB
[root@localhost usr]# 
[root@localhost usr]# docker rmi -f wuubuntu:1.2
Untagged: wuubuntu:1.2
Deleted: sha256:21423a381c8c6769e410a20d3cf11d773c1caad29ea1c1ecadb7c6c197033e88
Deleted: sha256:ef4795b52a13423fe8fa35cd9ec3f2ec4977474cda1d12279ae70af25d097b59
[root@localhost usr]# 
[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED        SIZE
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago   177MB
wu/ubuntu                                                  latest    9fd000d64b52   2 days ago     72.8MB
redis                                                      latest    7614ae9453d1   2 years ago    113MB
registry                                                   latest    b8604a3fe854   2 years ago    26.2MB
ubuntu                                                     latest    ba6acccedd29   2 years ago    72.8MB
[root@localhost usr]# 
[root@localhost usr]# curl -XGET http://192.168.153.128:5000/v2/_catalog
{"repositories":["wuubuntu"]}
[root@localhost usr]# [root@localhost usr]# docker pull 192.168.153.128:5000/wuubuntu:1.2
1.2: Pulling from wuubuntu
7b1a6ab2e44d: Already exists 
f224faf5dd6c: Pull complete 
Digest: sha256:e248a868f5367e4416b1e609bf46b2d01a241758488d6abc467cc0dfeb782a48
Status: Downloaded newer image for 192.168.153.128:5000/wuubuntu:1.2
192.168.153.128:5000/wuubuntu:1.2
[root@localhost usr]# 
[root@localhost usr]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED          SIZE
192.168.153.128:5000/wuubuntu                              1.2       21423a381c8c   29 minutes ago   126MB
registry.cn-hangzhou.aliyuncs.com/wuzhaobo_test/myubuntu   1.1       a32a52da6413   26 hours ago     177MB
wu/ubuntu                                                  latest    9fd000d64b52   2 days ago       72.8MB
redis                                                      latest    7614ae9453d1   2 years ago      113MB
registry                                                   latest    b8604a3fe854   2 years ago      26.2MB
ubuntu                                                     latest    ba6acccedd29   2 years ago      72.8MB
[root@localhost usr]# 
[root@localhost usr]# docker run -it 192.168.153.128:5000/wuubuntu:1.2 /bin/bash
root@d4a076e9949e:/# 
root@d4a076e9949e:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)RX packets 7  bytes 578 (578.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@d4a076e9949e:/# 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词