Docker学习之镜像管理(超详解析)

2024-03-15 20:44

本文主要是介绍Docker学习之镜像管理(超详解析),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Docker镜像生命周期(可以把docker镜像理解为虚拟机镜像)

实验内容:

搜索官方仓库镜像

[root@localhost ~]# docker search busybox //以查找busybox为例
搜索说明:name镜像名称   description镜像说明   stars点赞数量  official是否是官方的  automated是否是自动构建的
NAME                                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
busybox                             Busybox base image.                             3225                [OK]                
radial/busyboxplus                  Full-chain, Internet enabled, busybox made f…   56                                      [OK]
yauritux/busybox-curl               Busybox with CURL                               25                                      
arm32v7/busybox                     Busybox base image.                             10                                      
arm64v8/busybox                     Busybox base image.                             8                                       
odise/busybox-curl                                                                  4                                       [OK]
i386/busybox                        Busybox base image.                             3                                       
s390x/busybox                       Busybox base image.                             3                                       
prom/busybox                        Prometheus Busybox Docker base images           2                                       [OK]
p7ppc64/busybox                     Busybox base image for ppc64.                   2                                       
hugegraph/busybox                   test image                                      2                                       
joeshaw/busybox-nonroot             Busybox container with non-root user nobody     2                                       
busybox42/zimbra-docker-centos      A Zimbra Docker image, based in ZCS 8.8.9 an…   2                                       [OK]
openebs/busybox-client                                                              1                                       
amd64/busybox                       Busybox base image.                             1                                       
vukomir/busybox                     busybox and curl                                1                                       
ppc64le/busybox                     Busybox base image.                             1                                       
privatebin/chown                     Docker image providing busybox' chown, stat…   1                                       
antrea/busybox                                                                      1                                       
spotify/busybox                     Spotify fork of https://hub.docker.com/_/bus…   1                                       
busybox42/nginx_php-docker-centos   This is a nginx/php-fpm server running on Ce…   1                                       [OK]
busybox42/haraka-docker-centos      CentOS Haraka build with spamassassin, redis…   1                                       [OK]
busybox42/alpine-pod                                                                0                                       
rancher/busybox                                                                     0                                       
concourse/busyboxplus                                                               0   

拉取镜像

[root@localhost ~]# docker pull busybox //拉取busybox(不指定版本时,默认拉取最近版本)
Using default tag: latest
latest: Pulling from library/busybox
5cc84ad355aa: Pull complete 
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Downloaded newer image for busybox:latest
[root@localhost ~]# docker pull ubuntu:18.04  //拉取ubuntu(也可以指定版本拉取)
18.04: Pulling from library/ubuntu
284055322776: Pull complete 
Digest: sha256:0fedbd5bd9fb72089c7bbca476949e10593cebed9b1fb9edf5b79dbbacddd7d6
Status: Downloaded newer image for ubuntu:18.04
[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/kongd/openlab:ubuntu_18.04 //由于docker拉取时是基于docker hub有时国内站点访问时可能会速度较慢,所以可以指定拉取国内阿里等站点的,也可以自己构建docker镜像站进行拉取。这里不做过多赘述。
ubuntu_18.04: Pulling from kongd/openlab
Digest: sha256:fc0d6af5ab38dab33aa53643c4c4b312c6cd1f044c1a2229b2743b252b9689fc
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/kongd/openlab:ubuntu_18.04

查看镜像信息

查看当前主机列表
[root@localhost ~]# docker images(也可以使用docker image ls命令来查看)
REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
busybox                                           latest              beae173ccac6        2 years ago         1.24MB
ubuntu                                            18.04               5a214d77f5d7        2 years ago         63.1MB
registry.cn-hangzhou.aliyuncs.com/kongd/openlab   ubuntu_18.04        5a214d77f5d7        2 years ago         63.1MB
查看镜像详细信息
[root@localhost ~]# docker inspect busybox //在此以查看busybox镜像信息为例
[{"Id": "sha256:beae173ccac6ad749f76713cf4440fe3d21d1043fe616dfbe30775815d1d0f6a","RepoTags": ["busybox:latest"],"RepoDigests": ["busybox@sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678"],"Parent": "","Comment": "","Created": "2021-12-30T19:19:41.006954958Z","Loaded": "2024-03-13T16:37:54.485607571+08:00","Container": "a0007fa726185ffbcb68e90f8edabedd79a08949f32f4f0bcc6e5fed713a72c8","ContainerConfig": {"Hostname": "a0007fa72618","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd": ["/bin/sh","-c","#(nop) ","CMD [\"sh\"]"],"Image": "sha256:da658412c37aa24e561eb7e16c61bc82a9711340d8fb5cf1a8f39d8e96d7f723","Volumes": null,"WorkingDir": "","Entrypoint": null,"OnBuild": null,"Labels": {},"Annotations": null},"DockerVersion": "20.10.7","Author": "","Config": {"Hostname": "","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd": ["sh"],"Image": "sha256:da658412c37aa24e561eb7e16c61bc82a9711340d8fb5cf1a8f39d8e96d7f723","Volumes": null,"WorkingDir": "","Entrypoint": null,"OnBuild": null,"Labels": null,"Annotations": null},"Architecture": "amd64","Os": "linux","Size": 1239820,"VirtualSize": 1239820,"GraphDriver": {"Data": {"MergedDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/merged","UpperDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/diff","WorkDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/work"},"Name": "overlay2"},"RootFS": {"Type": "layers","Layers": ["sha256:01fd6df81c8ec7dd24bbbd72342671f41813f992999a3471b9d9cbc44ad88374"]},"Metadata": {"LastTagTime": "0001-01-01T00:00:00Z"}}
]

删除镜像

[root@localhost ~]# docker rmi ubuntu:18.04(也可用docker image rm ubuntu:18.04命令完成)如果删除时需要进行强制删除可以采用-f参数
Untagged: ubuntu:18.04
Untagged: ubuntu@sha256:0fedbd5bd9fb72089c7bbca476949e10593cebed9b1fb9edf5b79dbbacddd7d6
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              beae173ccac6        2 years ago         1.24MB
myubuntu            18.04               5a214d77f5d7        2 years ago         63.1MB

导出导入镜像

ip主机名
192.168.27.137导出
192.168.27.141导入
导出
[root@localhost ~]# docker save -o images.tar busybox:latest myubuntu:18.04
-o:指定导出镜像的位置;
可以同时导出多个镜像;为一个文件;
指定.tar.gz 可以导出并压缩。
[root@localhost ~]# scp images.tar 192.168.27.137:~
The authenticity of host '192.168.27.137 (192.168.27.137)' can't be established.
ED25519 key fingerprint is SHA256:wKCxBY5GtfgHv2MW283QFPMTGf6L4CqjVBroqsX6wso.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.27.137' (ED25519) to the list of known hosts.Authorized users only. All activities may be monitored and reported.
root@192.168.27.137's password: 
images.tar          100%   64MB 254.7MB/s   00:00  
导入
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@localhost ~]# ll
总用量 65420
-rw-------. 1 root root      706  1月 23 19:05 anaconda-ks.cfg
-rw-------  1 root root 66983424  3月 13 17:00 images.tar
[root@localhost ~]# docker load -i images.tar 
01fd6df81c8e: Loading layer  1.459MB/1.459MB
Loaded image: busybox:latest
824bf068fd3d: Loading layer  65.51MB/65.51MB
Loaded image: myubuntu:18.04
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              beae173ccac6        2 years ago         1.24MB
myubuntu            18.04               5a214d77f5d7        2 years ago         63.1MB

这篇关于Docker学习之镜像管理(超详解析)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/813211

相关文章

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

SpringBoot中使用 ThreadLocal 进行多线程上下文管理及注意事项小结

《SpringBoot中使用ThreadLocal进行多线程上下文管理及注意事项小结》本文详细介绍了ThreadLocal的原理、使用场景和示例代码,并在SpringBoot中使用ThreadLo... 目录前言技术积累1.什么是 ThreadLocal2. ThreadLocal 的原理2.1 线程隔离2

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

docker如何删除悬空镜像

《docker如何删除悬空镜像》文章介绍了如何使用Docker命令删除悬空镜像,以提高服务器空间利用率,通过使用dockerimage命令结合filter和awk工具,可以过滤出没有Tag的镜像,并将... 目录docChina编程ker删除悬空镜像前言悬空镜像docker官方提供的方式自定义方式总结docker

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

MySQL 缓存机制与架构解析(最新推荐)

《MySQL缓存机制与架构解析(最新推荐)》本文详细介绍了MySQL的缓存机制和整体架构,包括一级缓存(InnoDBBufferPool)和二级缓存(QueryCache),文章还探讨了SQL... 目录一、mysql缓存机制概述二、MySQL整体架构三、SQL查询执行全流程四、MySQL 8.0为何移除查

在Rust中要用Struct和Enum组织数据的原因解析

《在Rust中要用Struct和Enum组织数据的原因解析》在Rust中,Struct和Enum是组织数据的核心工具,Struct用于将相关字段封装为单一实体,便于管理和扩展,Enum用于明确定义所有... 目录为什么在Rust中要用Struct和Enum组织数据?一、使用struct组织数据:将相关字段绑

使用Java实现一个解析CURL脚本小工具

《使用Java实现一个解析CURL脚本小工具》文章介绍了如何使用Java实现一个解析CURL脚本的工具,该工具可以将CURL脚本中的Header解析为KVMap结构,获取URL路径、请求类型,解析UR... 目录使用示例实现原理具体实现CurlParserUtilCurlEntityICurlHandler

深入解析Spring TransactionTemplate 高级用法(示例代码)

《深入解析SpringTransactionTemplate高级用法(示例代码)》TransactionTemplate是Spring框架中一个强大的工具,它允许开发者以编程方式控制事务,通过... 目录1. TransactionTemplate 的核心概念2. 核心接口和类3. TransactionT

数据库使用之union、union all、各种join的用法区别解析

《数据库使用之union、unionall、各种join的用法区别解析》:本文主要介绍SQL中的Union和UnionAll的区别,包括去重与否以及使用时的注意事项,还详细解释了Join关键字,... 目录一、Union 和Union All1、区别:2、注意点:3、具体举例二、Join关键字的区别&php