前言
前面已经介绍了如何安装docker和配置docker的阿里云镜像地址,那么这里安静简单的介绍下一些镜像的简单操作
启动镜像
安静安装完成Docker后,并没有在上面安装其他的镜像文件,然后直接通过 Docker run 镜像名 进行启动镜像。
这里通过上图可以看到,docker查看本地有没有镜像,如果没有的话就去docker hub上进行查找,如果存在这个镜像,就进行下载下来。安静在随便启动一个镜像,就会报错了,表示找不到这个镜像文件
其他操作
可以通过 docker run --help 进行查看docker启动容器镜详细命令,这里安静简单的介绍下我们常用到的几个参数
# 启动docker docker run [OPTIONS] IMAGE [COMMAND][ARG...] # 常用参数说明 --name="Name" # 给容器指定一个名字 -d # 后台方式运行容器,并返回容器的id! -i # 以交互模式运行容器,通过和 -t 一起使用 -t # 给容器重新分配一个终端,通常和 -i 一起使用 -P # 随机端口映射(大写) -p # 指定端口映射(小结),一般可以有四种写法
查看本地镜像
如果不知道本地有什么镜像,我们可以通过 docker images 进行查看,显示的是我们本地所有的镜像文件
[root@anjing anjing]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB REPOSITORY # 表示镜像名称 TAG # 表示镜像的版本标签 IMAGE ID # 表示镜像的ID CREATED # 表示镜像的创建时间 SIZE # 表示镜像的大小
其他参数
-a :表示查看本地所有镜像
-q:表示只显示镜像ID
帮助文档
如果不知道具体使用方法,我们可以通过 docker images --help 进行查看
[root@anjing ~]# docker images --help Usage: docker images [OPTIONS] [REPOSITORY[:TAG]] List images Options: -a, --all Show all images (default hides intermediate images) --digests Show digests -f, --filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template --no-trunc Don't truncate output -q, --quiet Only show image IDs [root@anjing ~]#
查找镜像
当我们想要搜索镜像看看是否存在的时候,我们可以通过 docker search 镜像名 进行查看docker hub上是否存在。存在就返回对应的信息,如果不存在就返回为空
# 查找存在的镜像名 [root@anjing ~]# docker search jenkins NAME DESCRIPTION STARS OFFICIAL AUTOMATED jenkins DEPRECATED; use "jenkins/jenkins:lts" instead 5384 [OK] jenkins/jenkins The leading open source automation server 2793 jenkinsci/blueocean https://jenkins.io/projects/blueocean 657 # 查找不存在的镜像名 [root@anjing ~]# docker search anjing666 NAME DESCRIPTION STARS OFFICIAL AUTOMATED
帮助文档
如果不清楚具体使用方法,我们通过 docker search --help 看具体帮助文档
[root@anjing ~]# docker search --help Usage: docker search [OPTIONS] TERM Search the Docker Hub for images Options: -f, --filter filter Filter output based on conditions provided --format string Pretty-print search using a Go template --limit int Max number of search results (default 25) --no-trunc Don't truncate output
下载镜像
通过上面命令搜索到了想要下载的镜像,就可以通过 docker pull 镜像名 进行下载镜像。这里默认下载时最新版本。
[root@anjing ~]# docker pull jenkins Using default tag: latest latest: Pulling from library/jenkins 55cbf04beb70: Pull complete 1607093a898c: Pull complete 9a8ea045c926: Pull complete d4eee24d4dac: Pull complete c58988e753d7: Pull complete 794a04897db9: Pull complete 70fcfa476f73: Pull complete 0539c80a02be: Pull complete 54fefc6dcf80: Pull complete 911bc90e47a8: Pull complete 38430d93efed: Pull complete 7e46ccda148a: Pull complete c0cbcb5ac747: Pull complete 35ade7a86a8e: Pull complete aa433a6a56b1: Pull complete 841c1dd38d62: Pull complete b865dcb08714: Pull complete 5a3779030005: Pull complete 12b47c68955c: Pull complete 1322ea3e7bfd: Pull complete Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668 Status: Downloaded newer image for jenkins:latest docker.io/library/jenkins:latest
指定版本下载
我们想要指定版本下载,首先要去docker hub上查看对应镜像是否存在当前版本。Docker hub仓库(https://hub.docker.com/)
在进行安装的时候执行对应的版本号 docker pull xxxx:xxx
[root@anjing ~]# docker pull jenkins:2.60.3 2.60.3: Pulling from library/jenkins Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668 Status: Downloaded newer image for jenkins:2.60.3 docker.io/library/jenkins:2.60.3
通过查看本地存在哪些docker可以看出来有2个不同的jenkins版本
[root@anjing ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB jenkins 2.60.3 cd14cecfdb3a 3 years ago 696MB jenkins latest cd14cecfdb3a 3 years ago 696MB
帮助文档
同样我们可以通过 docker pull --help 进行查看对应的帮助文档
[root@anjing ~]# docker pull --help Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] Pull an image or a repository from a registry Options: -a, --all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true) --platform string Set platform if server is multi-platform capable -q, --quiet Suppress verbose output
删除镜像
如果想要删除镜像的话,可以通过 docker rmi 进行删除镜像
[root@anjing ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB jenkins 2.60.3 cd14cecfdb3a 3 years ago 696MB jenkins latest cd14cecfdb3a 3 years ago 696MB [root@anjing ~]# docker rmi -f feb5d9fea6a5 Untagged: hello-world:latest Untagged: hello-world@sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685 Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 [root@anjing ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins 2.60.3 cd14cecfdb3a 3 years ago 696MB jenkins latest cd14cecfdb3a 3 years ago 696MB
通过执行上述命令发现我们已经成功的将镜像进行了删除
其他用法
如果想要删除更多或者全部的话我们可以也可以通过 docker rmi 后面跟上不同的参数
删除单个:docker rmi -f 镜像id
删除多个:docker rmi -f 镜像名:tag 镜像名:tag
删除全部:docker rmi -f(docker images -qa)