- Docker—常用镜像命令
- docker images:
- 示例:
- docker-search:
- 示例一:
- 示例二:
- docker-pull :
- 示例:
- docker-rmi
- 示例:
docker images:
docker images : 用于查看本地镜像.并返回 5 个选项分别是:
| REPOSITORY | TAG | IMAGE ID | CREATED | SIZE |
|---|---|---|---|---|
| 镜像仓库员 | 镜像的标签 | 镜像ID | 镜像创建的时间 | 镜像大小 |
[root@StrawberryJam home]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 7 months ago 13.3kB
另外需要注意到是,同一个仓源可以有多个TAG ,代表这个仓库源不同的版本,我们使用REPOSITORY : TAG ,来定义不同的镜像.如果你不指定一个镜像的TAG ,例如你只使用ubuntu,Docker将默认使用ubuntu:latest(最新版本的)镜像
另外,docker images 还提供了更多的OPTIONS(选项),使用说明如下:
- docker images -a : 查看所有镜像 (含中间映像层)
- docker images -q : 只看镜像的ID
- docker images --digests : digests :显示镜像的摘要信息
- docker images--no-trunc :显示完整的镜像信息
docker-search:
这个命令就非常的有意思了,docker-search 命令是要从DockerHub 网站上查找镜像,也就是从这个网址https://hub.docker.com/查找镜像.
示例一:比如说我们查找关于Golang编程语言的镜像:
[root@StrawberryJam home]# docker search golang NAME DESCRIPTION STARS OFFICIAL AUTOMATED golang Go (golang) is a general purpose, higher-lev… 3297 [OK] ilanyu/golang-reverseproxy golang-ReverseProxy 87 [OK] circleci/golang CircleCI images for Go 15 [OK] golangci/golangci-lint 15 dockercore/golang-cross An image used to cross compile golang. It in… 6 [OK] desertbit/golang-gb Golang GB Docker Image 4 [OK] mxschmitt/golang_url_shortener URL Shortener written in Golang using Bolt D… 4 portainer/golang-builder Utility to build Golang binaries. 4 [OK] instructure/golang Instructure base golang image 2 [OK] theyorkshiredev/golang-git A custom container with Golang and Git insta… 2 [OK] golangci/build-runner Image for running analysis (build) for https… 1
虽然出来了一大堆英文,但也就5列字段而已,分别是:
| NAME | DESCRIPTION | STARS | OFFICIAL | AUTOMATED |
|---|---|---|---|---|
| 镜像名称 | 镜像描述 | 获赞(星星)数 | 是否是官方镜像 | 自动构建(这个不用管) |
同样我们也可以从Dock.hub官网查看我们搜索的到底是什么
我们可以看到,第一个就是Golang官方版,星星数有3.3k,也是和我们上面的搜索内容对应上的.这里还有更有趣的操作,比如根据获赞数返回搜索结果,
搜索获赞(星星)等于等于15的镜像,使用命令docker search --filter=stars=NUM即可
[root@StrawberryJam home]# docker search --filter=stars=15 golang NAME DESCRIPTION STARS OFFICIAL AUTOMATED golang Go (golang) is a general purpose, higher-lev… 3297 [OK] ilanyu/golang-reverseproxy golang-ReverseProxy 87 [OK] circleci/golang CircleCI images for Go 15 [OK] golangci/golangci-lint 15
更多命令使用说明如下:
- docker search --no-trunc golang : 显示完整的镜像描述
- docker search --automated golang :只列出 automated build类型的镜像
docker-pull :
该命令是从 Docker Hub上拉取镜像,(类似GitHub),比如我们就拉取上面 Golang的官方镜像
示例:[root@StrawberryJam home]# docker pull golang Using default tag: latest latest: Pulling from library/golang d6ff36c9ec48: Pull complete c958d65b3090: Pull complete edaf0a6b092f: Pull complete 80931cf68816: Pull complete 813643441356: Pull complete a54c81388677: Pull complete 31748c757dd4: Pull complete Digest: sha256:174e1be71bd2aa8c65d6c17be0e5c0f8bc4e5ec03e82a5f57aad0b8acf22ef7f Status: Downloaded newer image for golang:latest docker.io/library/golang:latest
这里需要注意的是,如果直接使用docker pull golang默认的是docker pull golang:latest,也就是说下载最新的镜像,如果想指定版本,可以从官网查看
docker-rmi
镜像删除
直接使用强制删除就好了… = =, 比如删除hello-world,使用docker-rmi -f hello-world即可
[root@StrawberryJam home]# docker rmi -f hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202 Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b [root@StrawberryJam home]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE golang latest baaca3151cdb 26 hours ago 810MB
如果想清库(镜像全部删除),docker rmi -f $(docker images -q) 解君愁
| 如果文章对你有帮组的话,记得留个赞哦!! |



