温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

docker笔记8-镜像命令

发布时间:2020-08-09 19:40:23 来源:ITPUB博客 阅读:199 作者:czxin788 栏目:开发技术

    先回顾一下容器、存储、镜像三者之间的关系。

docker笔记8-镜像命令

    我们知道docker的logo是一条大鲸鱼背上驮着集装箱。那我们对应到docker如下:

    1)蓝色的大海里面------->宿主机系统比如我笔记本windows 7;

    2)鲸鱼---------->docker环境(yum install docker-ce)

    3)集装箱-------->容器实例(from 来自我们镜像模板)

docker images

    功能:列出本地主机上的镜像

[root@t-docker chenzx]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
test_web            latest              58b7fb33ace5        3 days ago          959MB

    选项说明:

REPOSITORY:表示镜像的仓库源
tag:镜像的标签
image id:镜像id
created:镜像的创建时间
size:镜像大小

    同一个仓库源可以有多个tag,代表这个仓库源的不同版本。我们使用REPOSITORY:TAG来定义不同的镜像。如果你不指定一个镜像的版本标签,例如你只使用centos,docker就默认使用docker:latest镜像

    OPTIONS说明:

    -a:列出本地所有的镜像(含中间映像层,因为镜像是分层的,-a会把所有层都显示出来)
    -q:只显示镜像id。
    --digests:显示镜像的摘要信息
    --no-trunc:显示完整的镜像信息,即IMAGE ID会显示完整

docker search

    功能:查找某个镜像名字

    网站:注意,即使你配置了阿里云加速,docker search命令查找的网站也是是 https://hub.docker.com。阿里云加速只是下载时才会被用到。

 [root@t-docker chenzx]# docker search tomcat

   画外音:仓库就是存放镜像的地方。

    -s:查找starts超过多少的镜像

[root@t-docker chenzx]# docker search -s 30  tomcat
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
tomcat              Apache Tomcat is an open source implementati…   1996                [OK]                
tomee               Apache TomEE is an all-Apache Java EE certif…   55                  [OK]                
dordoka/tomcat      Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   49                                      [OK

    --no-trunc:不减掉描述信息,即显示完整的描述信息

[root@t-docker chenzx]# docker search -s 30 --no-trunc tomcat
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME                DESCRIPTION                                                                                            STARS               OFFICIAL            AUTOMATED
tomcat              Apache Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies   1996                [OK]                
tomee               Apache TomEE is an all-Apache Java EE certified stack where Apache Tomcat is top dog.                  55                  [OK]                
dordoka/tomcat      Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 based docker container.                                        49                                      [OK]

    --automated:只列出automated build类型的镜像

docker pull

    功能:下载镜像

[root@t-docker chenzx]# docker search -s 30 tomcat
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
tomcat              Apache Tomcat is an open source implementati…   1996                [OK]                
tomee               Apache TomEE is an all-Apache Java EE certif…   55                  [OK]                
dordoka/tomcat      Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   49                                      [OK]
[root@t-docker chenzx]# 
[root@t-docker chenzx]# docker pull tomcat  #相当于tomcat:latest下载最新版本
[root@t-docker chenzx]# docker pull 192.168.0.106:5000/hello-world:v1.2  #这个表示指定仓库源下载镜像

docker rmi

    功能:删除某个镜像

    删除单个:docker rmi -f 镜像id

[root@t-docker chenzx]# docker rmi hello-world 
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 85296d21d05c is using its referenced image 2cb0d9787c4d
[root@t-docker chenzx]# docker rmi -f hello-world  #如果容器正在运行会删不掉,可以加-f强制删除
Untagged: hello-world:latest
Untagged: hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Deleted: sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34

    删除多个:docker rmi -f 镜像1:tag 镜像2:tag,不写tag,删除的就是latest

    删除全部:docker rmi -f $(docker images -qa)

docker save and load(保存镜像和加载镜像)

    功能: 镜像名 用户名 主机名 'cat | docker load'

docker tag

    功能:给镜像打标签:

[root@k8s-node3 ~]# docker images
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
mysql                                         5.7.22              6bb891430fb6        3 months ago        372 MB
[root@k8s-node3 ~]# docker tag mysql:5.7.22 docker-registry:5000/mysql:5.7.22
[root@k8s-node3 ~]# docker images
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
docker-registry:5000/mysql                    5.7.22              6bb891430fb6        3 months ago        372 MB
mysql                                         5.7.22              6bb891430fb6        3 months ago        372 MB

    删除镜像的标签:

[root@k8s-node3 ~]# docker rmi -f  docker-registry:5000/mysql:5.7.22
Untagged: docker-registry:5000/mysql:5.7.22



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI