【Docker入门 二】image 镜像命令

Docker image 镜像

参考官网: https://docs.docker.com/engine/reference/run/
命令很多和Linux操作系统一样,要想全部记住,太麻烦了,只用记住常见的几个基本就够用了,其他的用到了,了解一下,知道什么时候用什么命令,知道怎么去查就行了。

基本命令

  • 最基础的命令
docker version    # 显示docker的版本信息。
docker info       # 显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help # 帮助命令

docker 镜像常用命令

docker images 列出镜像信息

[root@instance-kdx3xlko rpm]# 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 numeric IDs

列出所有镜像

docker images -a  # 列出所有镜像
docker images -q  # 只显示镜像id
# 类似还支持管道
docker images | grep somevalue

官网示例 https://docs.docker.com/engine/reference/commandline/images/#examples

docker pull 下载镜像

首先去docker hub 搜索镜像查看对应版本信息 docker hub https://hub.docker.com/_/mysql

# 比如拉取 mysql 镜像
docker pull mysql
# 指定拉取mysql版本
docker pull mysql:5.7 

官网示例 https://docs.docker.com/engine/reference/commandline/pull/#examples

docker rmi 删除镜像

docker rmi -f 镜像id # 通过镜像id删除
docker rmi -f 镜像id 镜像id 镜像id 镜像id  # 删除多个镜像
docker rmi -f $(docker images -aq) # 删除全部的镜像(联合命令,先查出全部镜像id然后删除)

官网示例 https://docs.docker.com/engine/reference/commandline/rmi/#examples

docker inspect

查看镜像的元数据(详细数据)
官网描述 Return low-level information on Docker objects

docker inspect 镜像id

官网示例 https://docs.docker.com/engine/reference/commandline/inspect/#examples

参考

官网有更详细的命令解释

Command Description
docker image build Build an image from a Dockerfile # 从Dockerfile构建docker镜像
docker image history Show the history of an image # 显示镜像的历史
docker image import Import the contents from a tarball to create a filesystem image # 从tarball中导入内容创建一个文件系统镜像
docker image inspect Display detailed information on one or more images # 展示一个或多个镜像的详细信息
docker image load Load an image from a tar archive or STDIN # 从一个tar包或标准输入中加载一个镜像
docker image ls List images # 镜像列表
docker image prune Remove unused images # 移除为使用的镜像
docker image pull Pull an image or a repository from a registry # 从docker hub 拉取镜像或者仓库
docker image push Push an image or a repository to a registry # 推送镜像到 docker hub
docker image rm Remove one or more images # 移除一个或多个镜像
docker image save Save one or more images to a tar archive (streamed to STDOUT by default) # 保存一个或多个到tar包
docker image tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE # 创建一个镜像标签

总结

学这些命令,学起来还是很简单的,毕竟和Linux命令差不多,主要就是搞清楚概念,后面还有容器,数据卷之类的,还有联合文件系统。
概念多看些图示,理解起来就很快。

下一步

下一步练习下容器的命令,最终我会把我那个 https://github.com/CoderCharm/MallAPI 项目,使用Docker跑起来。算是一个小小的实践检测吧。

原文地址:https://www.cnblogs.com/CharmCode/p/13276613.html