您现在的位置是:首页 > 文章详情

常用Docker镜像操作命令

日期:2019-10-23点击:627

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

[root@iz2ze0lvzs71710m0jegmsz docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-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 jenkins NAME DESCRIPTION STARS OFFICIAL AUTOMATED jenkins Official Jenkins Docker image 4489 [OK] jenkins/jenkins The leading open source automation server 1742 jenkinsci/blueocean https://jenkins.io/projects/blueocean 449 jenkinsci/jenkins Jenkins Continuous Integration and Delivery … 373 jenkinsci/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 Base Jenkins slave docker image 58 [OK] jenkinsci/ssh-slave A Jenkins SSH Slave docker image 39 [OK] jenkins/slave base 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… 25 openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 20 bitnami/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 based on the Swarm plugin 8 [OK] openshift/jenkins-slave-base-centos7 A Jenkins slave base image. DEPRECATED: see … 6 publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 5 [OK] openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4 trion/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 (based on openshift jenkins 2… 0 [OK]

语法及常用参数:

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

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

[root@iz2ze0lvzs71710m0jegmsz docker]# docker pull tomcat Using default tag: latest latest: Pulling from library/tomcat 9a0b0ce99936: Pull complete db3b6004c61a: Pull complete f8f075920295: Pull complete 6ef14aff1139: Pull complete 962785d3b7f9: Pull complete 631589572f9b: Pull complete c55a0c6f4c7b: Downloading 379605d88e88: Download complete e056aa10ded8: Download complete 6349a1c98d85: Download complete latest: Pulling from library/tomcat 9a0b0ce99936: Pull complete db3b6004c61a: Pull complete f8f075920295: Pull complete 6ef14aff1139: Pull complete 962785d3b7f9: Pull complete 631589572f9b: Pull complete c55a0c6f4c7b: Pull complete 379605d88e88: Pull complete e056aa10ded8: Pull complete 6349a1c98d85: Pull complete Digest: sha256:77e41dbdf7854f03b9a933510e8852c99d836d42ae85cba4b3bc04e8710dc0f7 Status: Downloaded newer image for tomcat:latest docker.io/library/tomcat:latest

语法及常用参数:

[root@iz2ze0lvzs71710m0jegmsz docker]# docker pull --help Usage: 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/docs 3.当前运行的这个tomcat实例是一个没有文档内容的tomcat,以它为模板commit一个没有doc的tomcat新镜像xiaowang/mytomcat #docker commit -a="xiaowang" -m="del tomcat docs" 202ddd0513de xiaowang/mytomcat:1.2 4.分别启动我们的新镜像和之前的镜像查看区别 启动我们现在的xiaowang/mytomcat 发现它并没有doc 启动我们之前的tomcat 发现它的doc还是正常的
原文链接:https://yq.aliyun.com/articles/722380
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章