常用Docker镜像操作命令

简介: 一、docker images 列出本地主机上的镜像[root@iz2ze0lvzs71710m0jegmsz docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED ...

一、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还是正常的
相关文章
|
2天前
|
Docker 容器
docker:记录如何在x86架构上构造和使用arm架构的镜像
为了实现国产化适配,需将原x86平台上的Docker镜像转换为适用于ARM平台的镜像。本文介绍了如何配置Docker buildx环境,包括检查Docker版本、安装buildx插件、启用实验性功能及构建多平台镜像的具体步骤。通过这些操作,可以在x86平台上成功构建并运行ARM64镜像,实现跨平台的应用部署。
17 2
|
14天前
|
Java Docker 微服务
SpringBoot微服务打包Docker镜像
SpringBoot微服务打包Docker镜像
45 11
|
6天前
|
Go Docker Python
docker的python与go镜像的制作
docker的python与go镜像的制作
15 1
|
14天前
|
Docker 容器
用Docker发布自己的镜像
用Docker发布自己的镜像
45 9
|
8天前
|
安全 网络安全 开发者
Docker学习笔记(一):Docker命令总结
本文介绍了Docker的基本概念、优点以及常用命令。Docker是一个开源的应用容器引擎,它通过容器打包应用程序及其依赖项,实现快速部署和迁移。主要优点包括轻量级、可移植性、易于管理、安全性和开源性。文章还区分了镜像和容器的概念,并提供了构建镜像、查看容器、运行容器、停止和删除容器等常用Docker命令的示例。
85 0
|
13天前
|
Linux 网络安全 Docker
安装后无法使用 Docker 命令
【10月更文挑战第3天】
31 2
|
15天前
|
存储 安全 Ubuntu
docker中的镜像
【10月更文挑战第1天】
31 4
|
13天前
|
缓存 安全 Linux
docker镜像管理问题
【10月更文挑战第3天】
61 1
|
15天前
|
Docker 容器
docker的导入本地镜像和导出本地镜像
本文介绍了如何使用Docker对本地镜像进行导入和导出操作,包括从本地导入`nginx.tar`镜像以及将`open-webui`镜像导出并压缩为`open-webui.tar.gz`。
28 1
|
16天前
|
前端开发 应用服务中间件 nginx
docker运行nginx镜像
这篇文章详细说明了如何在Docker中部署并运行Nginx服务,包括拉取镜像、配置文件的挂载以及容器的启动配置。
76 0
docker运行nginx镜像