一、docker images 列出本地主机上的镜像

[root@iz2ze0lvzs71710m0jegmsz docker]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEhello-world         latest              fce289e99eb9        9 months ago        1.84kB

REPOSITORY----表示镜像的仓库源
TAG----表示镜像的标签
IMAGE ID----镜像ID
CREATED----镜像创建时间
SIZE----镜像大小

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

语法及常用参数:

Usage:    docker images [OPTIONS] [REPOSITORY[:TAG]]        Options:          -a: 列出本地所有的镜像          -q:只显示镜像ID          --digests:显示镜像的摘要信息          --no-trunc:显示完整的镜像信息               REPOSITORY就是镜像的ID        TAG就是标签(不写的话默认是last)

image

二、docker search 去docker hub仓库搜索某个镜像的名字

[root@iz2ze0lvzs71710m0jegmsz ~]# docker search jenkinsNAME                                   DE ION                                     STARS               OFFICIAL            AUTOMATEDjenkins                                Official Jenkins Docker image                   4489                [OK]jenkins/jenkins                        The leading open source automation server       1742jenkinsci/blueocean                    https://jenkins.io/projects/blueocean           449jenkinsci/jenkins                      Jenkins Continuous Integration and Delivery …   373jenkinsci/jnlp-slave                   A Jenkins slave using JNLP to establish conn…   114                                     [OK]jenkins/jnlp-slave                     a Jenkins agent (FKA "slave") using JNLP to …   97                                      [OK]jenkinsci/slave                          Jenkins slave docker image                 58                                      [OK]jenkinsci/ssh-slave                    A Jenkins SSH Slave docker image                39                                      [OK]jenkins/slave                            image for a Jenkins Agent, which includ…   34                                      [OK]cloudbees/jenkins-enterprise           CloudBees Jenkins Enterprise (Rolling releas…   34                                      [OK]xmartlabs/jenkins-android              Jenkins image for Android development.          26                                      [OK]h1kkan/jenkins-docker                   Extended Jenkins docker image, bundled wi…    25openshift/jenkins-2-centos7            A Centos7  d Jenkins v2.x image for use w…   20bitnami/jenkins                        Bitnami Docker Image for Jenkins                19                                      [OK]cloudbees/jenkins-operations-center    CloudBees Jenkins Operation Center (Rolling …   13                                      [OK]blacklabelops/jenkins                  Docker Jenkins Swarm-Ready with HTTPS and Pl…   13                                      [OK]vfarcic/jenkins-swarm-agent            Jenkins agent  d on the Swarm plugin         8                                       [OK]openshift/jenkins-slave- -centos7   A Jenkins slave   image. DEPRECATED: see …   6publicisworldwide/jenkins-slave        Jenkins Slave  d on Oracle Linux             5                                       [OK]openshift/jenkins-1-centos7            DEPRECATED: A Centos7  d Jenkins v1.x ima…   4trion/jenkins-docker-client            Jenkins CI server with docker client            3                                       [OK]ansibleplaybookbundle/jenkins-apb      An APB which deploys Jenkins CI                 1                                       [OK]mashape/jenkins                        Just a jenkins image with the AWS cli added …   0                                       [OK]amazeeio/jenkins-slave                 A jenkins slave that connects to a master vi…   0                                       [OK]jameseckersall/jenkins                 docker-jenkins ( d on openshift jenkins 2…   0                                       [OK]

语法及常用参数:

[root@iz2ze0lvzs71710m0jegmsz docker]# docker search --helpUsage:    docker search [OPTIONS] TERMOptions:--no-trunc:显示完整的镜像描述-s:列出收藏数不小于指定值的镜像eg:# docker search -s 30 jenkins

三、docker pull 拉取某个镜像到本地

[root@iz2ze0lvzs71710m0jegmsz docker]# docker pull tomcatUsing default tag: latestlatest: Pulling from library/tomcat9a0b0ce99936: Pull completedb3b6004c61a: Pull completef8f075920295: Pull complete6ef14aff1139: Pull complete962785d3b7f9: Pull complete631589572f9b: Pull completec55a0c6f4c7b: Downloading379605d88e88: Download completee056aa10ded8: Download complete6349a1c98d85: Download completelatest: Pulling from library/tomcat9a0b0ce99936: Pull completedb3b6004c61a: Pull completef8f075920295: Pull complete6ef14aff1139: Pull complete962785d3b7f9: Pull complete631589572f9b: Pull completec55a0c6f4c7b: Pull complete379605d88e88: Pull completee056aa10ded8: Pull complete6349a1c98d85: Pull completeDigest: sha256:77e41dbdf7854f03b9a933510e8852c99d836d42ae85cba4b3bc04e8710dc0f7Status: Downloaded newer image for tomcat:latestdocker.io/library/tomcat:latest

语法及常用参数:

[root@iz2ze0lvzs71710m0jegmsz docker]# docker pull --helpUsage:    docker pull [OPTIONS] NAME[:TAG|@DIGEST]Options:-a:下载仓库所有镜像--disable-content-trust :忽略镜像的校验,默认开启上面的例子没有写TAG是哪个版本,所有默认下载最新版本(tag为last的)

四、dcoker rmi删除某个镜像

删除单个:#docker rmi -f 镜像ID删除多个:#docker rmi -f 镜像名1:TAG 镜像名2:TAG删除全部:#docker rmi -f ${docker images -qa}

五、docker commit 提交容器副本使之称为新的镜像

docker commit -m="提交的描述信息" -a="作者" 容器ID 要创建的目标镜像名:[标签名]eg:#docker commit -a="xiaowang" -m="del tomcat docs" 202ddd0513de xiaowang/mytomcat:1.2上面这个命令案例演示(有条件的同学可以跟着敲一下):1.从Docker Hub上下载Tomcat镜像并在本地运行#docker run -it(-d) -p 8888:8080 tomcat-p 主机端口:docker容器端口-P 随机端口分配-it 终端交互-d 后台运行2.故意删除上一步镜像产生的Tomcat容器的文档#docker exec -it 202ddd0513de /bin/bash#rm -rf ./tomcat/webapps/docs3.当前运行的这个tomcat实例是一个没有文档内容的tomcat,以它为模板commit一个没有doc的tomcat新镜像xiaowang/mytomcat#docker commit -a="xiaowang" -m="del tomcat docs" 202ddd0513de xiaowang/mytomcat:1.24.分别启动我们的新镜像和之前的镜像查看区别启动我们现在的xiaowang/mytomcat  发现它并没有doc启动我们之前的tomcat   发现它的doc还是正常的
收藏 打印