docker将本地镜像pull到阿里云和registry

目录

一、上次到阿里云服务器

1、制作一个带有vim功能的Ubuntu镜像

2、在阿里云上面创建镜像仓库

3、从阿里云仓库中上传和拉取镜像

二、上传镜像到本地私有库registry

1、下载镜像docker registry

2、运行私有库registry,相当于本地有个私有docker hub。

3、制作一个带有ifconfig的Ubuntu镜像

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

5、将镜像修改符合私有库规范的tag

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

7、push推送到私服库

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

9、pull到本地并运行


一、上次到阿里云服务器

1、制作一个带有vim功能的Ubuntu镜像

docker pull ubuntu
docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    ba6acccedd29   2 years ago     72.8MB

docker run -it ubuntu
root@8b9f2522faa0:/# apt-get update   #先更新一下软件包列表
root@8b9f2522faa0:/# apt-get install vim -y
root@8b9f2522faa0:/# echo "hello world" > abc.tec    #随便添加一点信息
root@8b9f2522faa0:/# cat abc.tec 
hello world

按下Ctrl+p+q退出容器,容器不停止(如果直接使用exit,容器会停止运行,这样就不能制作镜像了)

# docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES
8b9f2522faa0   ubuntu    "bash"    5 minutes ago   Up 5 minutes             optimistic_wescoff

# docker commit -m="ubuntu add vim"  -a="haha" 8b9f2522faa0  ubuntuvim:3.23    
sha256:761b629328e8fb5ae1cd187d5a1b0c5f12107bcad6663b1cf8b89c93e5f5201a

# docker images                                     #查看制作好的镜像
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
ubuntuvim     3.23      761b629328e8   56 seconds ago   191MB

2、在阿里云上面创建镜像仓库

3、从阿里云仓库中上传和拉取镜像

直接复制示例中的代码

# docker login --username=aliyun8035446320 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

# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
ubuntuvim     3.23      761b629328e8   11 minutes ago   191MB
# docker tag 761b629328e8 registry.cn-hangzhou.aliyuncs.com/yoyo_chengdu/ubuntu:3.23

# docker push registry.cn-hangzhou.aliyuncs.com/yoyo_chengdu/ubuntu:3.23
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/yoyo_chengdu/ubuntu]
af91d09903b5: Pushed 
9f54eef41275: Pushed 
3.23: digest: sha256:f74cfb2e5ef2ad30cd14fb5da6dbbc6eae9870c4e973f181abff11cfc603f1de size: 741

# docker rmi -f 761b629328e8      #删除制作的镜像

# docker pull registry.cn-hangzhou.aliyuncs.com/yoyo_chengdu/ubuntu:3.23 #拉取镜像

# docker images
REPOSITORY                                              TAG       IMAGE ID       CREATED          SIZE
registry.cn-hangzhou.aliyuncs.com/yoyo_chengdu/ubuntu   3.23      761b629328e8   16 minutes ago   191MB

# docker run -it 761b629328e8
root@2fb3a6485a7f:/# cat abc.tec 
hello world           #查看信息是否还在

二、上传镜像到本地私有库registry

1、下载镜像docker registry

# docker pull registry

2、运行私有库registry,相当于本地有个私有docker hub。

docker run -d -p 5000:5000 -v /yoyo/myregistry/:/tmp/registry --privileged=true registry

3、制作一个带有ifconfig的Ubuntu镜像

#docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    ba6acccedd29   2 years ago   72.8MB

#docker run -it ba6acccedd29
root@32e09b37ba40:/# apt-get update 
root@32e09b37ba40:/# apt-get install net-tools -y

root@32e09b37ba40:/# 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
        inet6 fe80::42:acff:fe11:3  prefixlen 64  scopeid 0x20<link>
        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
        RX packets 8745  bytes 31390066 (31.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4426  bytes 243881 (243.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
再使用快捷键 Ctrl+p+q退出,容器继续在后台运行。

# docker ps
CONTAINER ID   IMAGE          COMMAND                   CREATED         STATUS         PORTS                                       NAMES
32e09b37ba40   ba6acccedd29   "bash"                    7 minutes ago   Up 7 minutes    
# docker commit -m="ifconfig cmd add" -a="yoyo" 32e09b37ba40 ifubuntu:3.24
sha256:f53ed00a420725a04c8ba4314c8cf839e640d79df898b4539d60c442d59a6975

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

# curl -XGET http://192.168.80.172:5000/v2/_catalog
{"repositories":[]}

5、将镜像修改符合私有库规范的tag

# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
ifubuntu     3.24      f53ed00a4207   2 minutes ago   124MB
# docker tag ifubuntu:3.24 192.168.80.172:5000/ifubuntu:3.24
# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED         SIZE
192.168.80.172:5000/ifubuntu   3.24      f53ed00a4207   3 minutes ago   124MB

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

# vim /etc/docker/daemon.json

, "insecure-registries":["192.168.80.172:5000"]  #重点逗号


#重启docker

7、push推送到私服库

# docker run -d -p 5000:5000 -v /yoyo/myregistry/:/tmp/registry --privileged=true registry
7cc7789c511f09f713993ee11e22dbb79a08ef00f1138f124610d2a19b4c221c
#重新启用私服库

# docker push 192.168.80.172:5000/ifubuntu:3.24
The push refers to repository [192.168.80.172:5000/ifubuntu]
cc42a815d1b0: Pushed 
9f54eef41275: Pushed 
3.24: digest: sha256:c58ea58f4c35f4ea8bd139bd5a9b3bdc8cc9a497abf581d2e50847ea419eb8b6 size: 741
 

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

# curl -XGET http://192.168.80.172:5000/v2/_catalog
{"repositories":["ifubuntu"]}

9、pull到本地并运行

#docker images
REPOSITORY                     TAG       IMAGE ID       CREATED          SIZE
ifubuntu                       3.24      f53ed00a4207   12 minutes ago   124MB
192.168.80.172:5000/ifubuntu   3.24      f53ed00a4207   12 minutes ago   124MB

# docker rmi -f f53ed00a4207 f53ed00a4207

# docker pull 192.168.80.172:5000/ifubuntu:3.24
3.24: Pulling from ifubuntu
7b1a6ab2e44d: Already exists 
7565baf88cb5: Pull complete 
Digest: sha256:c58ea58f4c35f4ea8bd139bd5a9b3bdc8cc9a497abf581d2e50847ea419eb8b6
Status: Downloaded newer image for 192.168.80.172:5000/ifubuntu:3.24
192.168.80.172:5000/ifubuntu:3.24

# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED          SIZE
192.168.80.172:5000/ifubuntu   3.24      f53ed00a4207   16 minutes ago   124MB

#运行刚刚拉取的镜像查看是否带有ifconfig命令

# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED          SIZE
192.168.80.172:5000/ifubuntu   3.24      f53ed00a4207   16 minutes ago   124MB
registry                       latest    b8604a3fe854   2 years ago      26.2MB
ubuntu                         latest    ba6acccedd29   2 years ago      72.8MB
# docker run -it f53ed00a4207
root@eaed85410974:/# 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

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-03-24 10:42:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-24 10:42:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-24 10:42:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-24 10:42:07       20 阅读

热门阅读

  1. 【VSTO开发】遍历 Ribbon 中的所有控件或按钮

    2024-03-24 10:42:07       22 阅读
  2. C语言UDP基础CS模型

    2024-03-24 10:42:07       22 阅读
  3. 关于阿里云的高级运维面试题

    2024-03-24 10:42:07       23 阅读
  4. 蓝桥杯刷题--python-30

    2024-03-24 10:42:07       24 阅读
  5. C#与三菱PLC网络模块通讯

    2024-03-24 10:42:07       22 阅读
  6. go实现tcp客户端

    2024-03-24 10:42:07       21 阅读
  7. [ESP32] 编码旋钮驱动

    2024-03-24 10:42:07       18 阅读
  8. 深度学习 (自动求导)

    2024-03-24 10:42:07       17 阅读
  9. 大模型产品整理

    2024-03-24 10:42:07       17 阅读