05尚硅谷周阳老师Docker-本地镜像发布到阿里云与私有库

博客主要围绕本地镜像发布到阿里云展开,重点介绍了本地镜像发布到私有库的相关内容,包括docker私有库简介,并给出了新镜像推送私服库的案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地镜像发布到阿里云

[root@node001 ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
vlu/mybuntu      1.3       079bf1275a8a   3 hours ago     185MB
atguigu/ubuntu   3.7       7b40f602c178   16 hours ago    72.8MB
hello-world      <none>    9c7a54a9a43c   8 weeks ago     13.3kB
tomcat           latest    fb5657adc892   18 months ago   680MB
ubuntu           latest    ba6acccedd29   20 months ago   72.8MB
hello-world      latest    feb5d9fea6a5   21 months ago   13.3kB
redis            6.0.8     16ecd2772934   2 years ago     104MB
[root@node001 ~]# docker login --username=upward337 registry.cn-hangzhou.aliyuncs.com
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
 
Login Succeeded
[root@node001 ~]# docker tag 079bf1275a8a registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
[root@node001 ~]# docker push registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu]
1063fa79728f: Pushed 
9f54eef41275: Pushed 
1.3: digest: sha256:d776354d01cd8ec8fe5d260d3549a796db649497eb19e78c607a0d502373e3ab size: 741
[root@node001 ~]# docker rmi -f 079bf1275a8a
Untagged: vlu/mybuntu:1.3
Untagged: registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
Untagged: registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu@sha256:d776354d01cd8ec8fe5d260d3549a796db649497eb19e78c607a0d502373e3ab
Deleted: sha256:079bf1275a8a2e7aedd35132d2f4fafc407d799d1f9a3204ef97aed35da20a34
[root@node001 ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
atguigu/ubuntu   3.7       7b40f602c178   17 hours ago    72.8MB
hello-world      <none>    9c7a54a9a43c   8 weeks ago     13.3kB
tomcat           latest    fb5657adc892   18 months ago   680MB
ubuntu           latest    ba6acccedd29   20 months ago   72.8MB
hello-world      latest    feb5d9fea6a5   21 months ago   13.3kB
redis            6.0.8     16ecd2772934   2 years ago     104MB
[root@node001 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
1.3: Pulling from vlu001/myubuntu
7b1a6ab2e44d: Already exists 
b9250d242d06: Already exists 
Digest: sha256:d776354d01cd8ec8fe5d260d3549a796db649497eb19e78c607a0d502373e3ab
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu:1.3
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   4 hours ago     185MB
atguigu/ubuntu                                      3.7       7b40f602c178   17 hours ago    72.8MB
hello-world                                         <none>    9c7a54a9a43c   8 weeks ago     13.3kB
tomcat                                              latest    fb5657adc892   18 months ago   680MB
ubuntu                                              latest    ba6acccedd29   20 months ago   72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago   13.3kB
redis                                               6.0.8     16ecd2772934   2 years ago     104MB
[root@node001 ~]# docker run -it 079bf1275a8a /bin/bash
root@62afca1059d7:/# cat a.txt
Hello, apex !
root@62afca1059d7:/# exit
exit
[root@node001 ~]# 

本地镜像发布到私有库

docker私有库简介

新镜像推送私服库案例
[root@node001 ~]# 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@node001 ~]# docker run -d -p 5000:5000 -v /vlu001/myregistry/:/tmp/registry --privileged=true registry
2a00af7dfd7032f99ebd69d1e3a130244130bf118d26f5839b7db4ae394573a6
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED         STATUS         PORTS                                       NAMES
2a00af7dfd70   registry   "/entrypoint.sh /etc…"   9 seconds ago   Up 7 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   pedantic_hofstadter
[root@node001 ~]# docker run -it ubuntu /bin/bash
root@34282c0cb7a7:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2479 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [1066 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]    
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2856 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [28.5 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:11 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]                                                                              
Get:12 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]                                                                             
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3336 kB]                                                                           
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [31.2 kB]                                                                     
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [2618 kB]                                                                     
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1366 kB]                                                                       
Ign:16 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages                                                                                 
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [55.2 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [28.6 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1366 kB]
Fetched 27.3 MB in 44s (626 kB/s)                                                                                                                             
Reading package lists... Done
root@34282c0cb7a7:/# apt-get install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 46 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 2s (109 kB/s)     
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 4127 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
root@34282c0cb7a7:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
        RX packets 3139  bytes 28817367 (28.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2664  bytes 149121 (149.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
root@34282c0cb7a7:/# apt-get update[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED         STATUS         PORTS                                       NAMES
34282c0cb7a7   ubuntu     "/bin/bash"               3 minutes ago   Up 3 minutes                                               friendly_allen
2a00af7dfd70   registry   "/entrypoint.sh /etc…"   4 minutes ago   Up 4 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   pedantic_hofstadter
[root@node001 ~]# docker commit -m="ifconfig cmd add" -a="vlu" 34282c0cb7a7 ubuntu:1.2
sha256:7295d0d3bc7e2aad583d0be0ce721df37da026f0ada7ff81caa97899d4494677
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED          SIZE
ubuntu                                              1.2       7295d0d3bc7e   39 seconds ago   118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   5 hours ago      185MB
atguigu/ubuntu                                      3.7       7b40f602c178   18 hours ago     72.8MB
hello-world                                         <none>    9c7a54a9a43c   8 weeks ago      13.3kB
tomcat                                              latest    fb5657adc892   18 months ago    680MB
registry                                            latest    b8604a3fe854   19 months ago    26.2MB
ubuntu                                              latest    ba6acccedd29   20 months ago    72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago    13.3kB
redis                                               6.0.8     16ecd2772934   2 years ago      104MB
[root@node001 ~]# docker commit -m="ifconfig cmd add" -a="vlu" 34282c0cb7a7 vluubuntu:1.2
sha256:a1ed6fe2f61edb0708701a191cfee7fd238852422c0ac03d52c8bdd089d38ba6
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED          SIZE
vluubuntu                                           1.2       a1ed6fe2f61e   2 seconds ago    118MB
ubuntu                                              1.2       7295d0d3bc7e   55 seconds ago   118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   5 hours ago      185MB
atguigu/ubuntu                                      3.7       7b40f602c178   18 hours ago     72.8MB
hello-world                                         <none>    9c7a54a9a43c   8 weeks ago      13.3kB
tomcat                                              latest    fb5657adc892   18 months ago    680MB
registry                                            latest    b8604a3fe854   19 months ago    26.2MB
ubuntu                                              latest    ba6acccedd29   20 months ago    72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago    13.3kB
redis                                               6.0.8     16ecd2772934   2 years ago      104MB
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED         STATUS         PORTS                                       NAMES
34282c0cb7a7   ubuntu     "/bin/bash"               6 minutes ago   Up 6 minutes                                               friendly_allen
2a00af7dfd70   registry   "/entrypoint.sh /etc…"   7 minutes ago   Up 7 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   pedantic_hofstadter
[root@node001 ~]# docker stop 34282c0cb7a7
34282c0cb7a7
[root@node001 ~]# docker run -it a1ed6fe2f61e /bin/bash
root@dba80c0be4b2:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 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 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
root@dba80c0be4b2:/# exit
exit
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED          STATUS          PORTS                                       NAMES
2a00af7dfd70   registry   "/entrypoint.sh /etc…"   10 minutes ago   Up 10 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   pedantic_hofstadter
[root@node001 ~]# curl -XGET localhost:5000/v2/_catalog
{"repositories":[]}
[root@node001 ~]# docker tag vluubuntu:1.2  node001:5000/vluubuntu:1.2
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
node001:5000/vluubuntu                              1.2       a1ed6fe2f61e   6 minutes ago   118MB
vluubuntu                                           1.2       a1ed6fe2f61e   6 minutes ago   118MB
ubuntu                                              1.2       7295d0d3bc7e   7 minutes ago   118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   5 hours ago     185MB
atguigu/ubuntu                                      3.7       7b40f602c178   18 hours ago    72.8MB
hello-world                                         <none>    9c7a54a9a43c   8 weeks ago     13.3kB
tomcat                                              latest    fb5657adc892   18 months ago   680MB
registry                                            latest    b8604a3fe854   19 months ago   26.2MB
ubuntu                                              latest    ba6acccedd29   20 months ago   72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago   13.3kB
redis                                               6.0.8     16ecd2772934   2 years ago     104MB
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# 
[root@node001 ~]# systemctl restart docker
[root@node001 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2023-06-30 16:11:01 CST; 11s ago
     Docs: https://docs.docker.com
 Main PID: 91325 (dockerd)
    Tasks: 22
   Memory: 39.7M
   CGroup: /system.slice/docker.service
           └─91325 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
 
6月 30 16:11:00 node001 systemd[1]: Starting Docker Application Container Engine...
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.026121388+08:00" level=info msg="Starting up"
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.093318029+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.109971953+08:00" level=info msg="Loading containers: start."
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.523314196+08:00" level=info msg="Default bridge (docker0) is assigned with an IP... address"
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.696663932+08:00" level=info msg="Loading containers: done."
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.764634247+08:00" level=info msg="Docker daemon" commit=463850e graphdriver=overl...on=24.0.1
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.764890475+08:00" level=info msg="Daemon has completed initialization"
6月 30 16:11:01 node001 dockerd[91325]: time="2023-06-30T16:11:01.851761793+08:00" level=info msg="API listen on /run/docker.sock"
6月 30 16:11:01 node001 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@node001 ~]# docker run -d -p 5000:5000 -v /vlu001/myregistry/:/tmp/registry --privileged=true registry
cc3bf2e8380c4ff10d80fb244bb6317dc0c829c0d16e20e6b72238308f4f6e91
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED          SIZE
vluubuntu                                           1.2       a1ed6fe2f61e   15 minutes ago   118MB
node001:5000/vluubuntu                              1.2       a1ed6fe2f61e   15 minutes ago   118MB
ubuntu                                              1.2       7295d0d3bc7e   16 minutes ago   118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   5 hours ago      185MB
atguigu/ubuntu                                      3.7       7b40f602c178   18 hours ago     72.8MB
hello-world                                         <none>    9c7a54a9a43c   8 weeks ago      13.3kB
tomcat                                              latest    fb5657adc892   18 months ago    680MB
registry                                            latest    b8604a3fe854   19 months ago    26.2MB
ubuntu                                              latest    ba6acccedd29   20 months ago    72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago    13.3kB
redis                                               6.0.8     16ecd2772934   2 years ago      104MB
[root@node001 ~]# docker push node001:5000/vluubuntu:1.2
The push refers to repository [node001:5000/vluubuntu]
3d9af5f8278d: Pushed 
9f54eef41275: Pushed 
1.2: digest: sha256:00ee8d19398c17b01d6e9a87cc051979ad17f7cd54a91e0112b10f85454899e5 size: 741
[root@node001 ~]# curl -XGET localhost:5000/v2/_catalog
{"repositories":["vluubuntu"]}
[root@node001 ~]# 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值