Docker镜像基本命令

镜像相关命令

[root@docker ~]# docker --help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Log in to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.11.1)
  compose*    Docker Compose (Docker Inc., v2.19.1)
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon
                           (overrides DOCKER_HOST env var and default context
                           set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info", "warn",
                           "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Run 'docker COMMAND --help' for more information on a command.

可以查更详细的介绍例如Docker的版本

[root@docker ~]# docker version --help

Usage:  docker version [OPTIONS]

Show the Docker version information

Options:
  -f, --format string   Format output using a custom template:
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go
                        template.
                        Refer to https://docs.docker.com/go/formatting/ for
                        more information about formatting output with templates

[root@docker ~]# docker version -f'{{json .}}'  #-f和-format是一样的
{"Client":{"Platform":{"Name":"Docker Engine - Community"},"Version":"24.0.4","ApiVersion":"1.43","DefaultAPIVersion":"1.43","GitCommit":"3713ee1","GoVersion":"go1.20.5","Os":"linux","Arch":"amd64","BuildTime":"Fri Jul  7 14:54:21 2023","Context":"default"},"Server":{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"24.0.4","Details":{"ApiVersion":"1.43","Arch":"amd64","BuildTime":"Fri Jul  7 14:53:26 2023","Experimental":"false","GitCommit":"4ffc614","GoVersion":"go1.20.5","KernelVersion":"3.10.0-1160.el7.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.6.21","Details":{"GitCommit":"3dce8eb055cbb6872793272b4f20ed16117344f8"}},{"Name":"runc","Version":"1.1.7","Details":{"GitCommit":"v1.1.7-0-g860f061"}},{"Name":"docker-init","Version":"0.19.0","Details":{"GitCommit":"de40ad0"}}],"Version":"24.0.4","ApiVersion":"1.43","MinAPIVersion":"1.12","GitCommit":"4ffc614","GoVersion":"go1.20.5","Os":"linux","Arch":"amd64","KernelVersion":"3.10.0-1160.el7.x86_64","BuildTime":"2023-07-07T14:53:26.000000000+00:00"}}

看版本

[root@docker ~]# docker version -f'{{.Server.Version}}'
24.0.4

pull

[root@docker ~]# docker pull --help

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Download an image from a registry

Aliases:
  docker image pull, docker pull

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

拉取zookeeper,pull 命令中的也可以不写,此时默认的为 latest。

[root@docker ~]# docker pull zookeeper
Using default tag: latest
latest: Pulling from library/zookeeper
a2abf6c4d29d: Pull complete 
2bbde5250315: Pull complete 
202a34e7968e: Pull complete 
4e4231e30efc: Pull complete 
707593b95343: Pull complete 
b070e6dedb4b: Pull complete 
46e5380f3905: Pull complete 
8b7e330117e6: Pull complete 
Digest: sha256:2c8c5c2db6db22184e197afde13e33dad849af90004c330f20b17282bcd5afd7
Status: Downloaded newer image for zookeeper:latest
docker.io/library/zookeeper:latest

加上选项-q 后就可简化拉取过程中的日志输出。抑制冗长输出)

docker pull -q zookeeper
docker.io/library/zookeeper:latest

docker pull 可通过镜像的 digest 进行拉取。语法格式为 docker pull @。
在这里插入图片描述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-J6hU7Xia-1689872829131)(…/…/…/…/Snipaste/03%E3%80%90%E7%94%B5%E8%84%91%E6%88%AA%E5%9B%BE%E8%BD%AF%E4%BB%B6%E3%80%91snipaste%E6%88%AA%E5%9B%BE%E8%BD%AF%E4%BB%B6/Typora/docker/%E9%95%9C%E5%83%8F/pull.png)]

docker pull nginx@sha256:1bb5c4b86cb7c1e9f0209611dc2135d8a2c1c3a6436163970c99193787d067ea

images

介绍

在 Docker 中,docker images 是一个用于查看本地主机上已下载的 Docker 镜像列表的命令。Docker 镜像是构建和运行容器的基础,它们包含了一个完整的应用程序运行环境以及所需的所有依赖项。以下是 docker images 命令的详细介绍:

命令格式

docker images [OPTIONS] [REPOSITORY[:TAG]]

常用选项

  • -a, --all: 显示所有镜像,包括中间层的镜像(通常被称为dangling镜像)。
  • --digests: 显示镜像的摘要信息。
  • --no-trunc: 显示完整的镜像ID。
  • --quiet, -q: 只显示镜像ID,不显示其他信息。

输出列
docker images 命令的输出包含以下列:

  • REPOSITORY:镜像的仓库名,通常由仓库名和镜像名组成。
  • TAG:镜像的标签,表示镜像的版本或不同的配置。
  • IMAGE ID:镜像的唯一ID。
  • CREATED:镜像的创建时间。
  • SIZE:镜像的大小。

镜像状态

  • <none>:如果镜像没有标签,即标签为空,那么镜像的标签列将显示 <none>
  • <none>(<none>):如果镜像被构建时出现错误,或者构建过程中未能成功生成完整的镜像,标签列会显示 <none> 和一对尖括号。

详细说明

  • REPOSITORY 是一个镜像的名称,它包括了仓库名和镜像名,通常以 <仓库名>/<镜像名> 的形式显示,例如 ubuntunginx
  • TAG 表示镜像的版本或不同的配置,例如 latest1.0stable 等。
  • IMAGE ID 是每个镜像的唯一标识符,是一个长字符串,用于在操作镜像时标识它们。
  • CREATED 列显示镜像的创建时间,以相对于当前时间的时间戳或日期形式显示。
  • SIZE 列显示镜像的大小,通常以字节为单位,也可以显示为人类可读的大小(如 MB、GB)。

使用示例

# 查看本地所有镜像

docker images

# 查看所有镜像的完整信息,包括摘要信息

docker images --digests

# 只显示镜像的ID

docker images --quiet

# 显示所有镜像,包括中间层(dangling)镜像

docker images -a

总结来说,docker images 命令是一个用于查看本地主机上已下载的 Docker 镜像列表的简单而有用的命令。通过了解已有的镜像,你可以更好地管理和使用它们,以满足应用程序的部署和运行需求。

例子

[root@docker ~]# docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Aliases:
  docker image ls, docker image list, docker 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   Format output using a custom template:
                        'table':            Print output in table format with
                        column headers (default)
                        'table TEMPLATE':   Print output in table format using
                        the given Go template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go
                        template.
                        Refer to https://docs.docker.com/go/formatting/ for
                        more information about formatting output with templates
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs

查看完整镜像 ID

默认的 docker images 显示的镜像 id 是经过截取后的显示结果,仅显示了前 12 位。使用 --no-trunc 参数后显示的是完成的镜像 id。

–digests选项可以查看所有镜像或指定镜像的digest信息。关于digest后面会详细学习。

[root@docker ~]# docker images --no-trunc/--digests
REPOSITORY    TAG       IMAGE ID                                                                  CREATED         SIZE
hello-world   latest    sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d   2 months ago    13.3kB
zookeeper     latest    sha256:36c607e7b14df07e3976ebe6216db9aabd41ef0884f73d4e6b5ccf5d44d9c195   19 months ago   278MB

查看指定镜像

[root@docker ~]# docker images hello-world
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    9c7a54a9a43c   2 months ago   13.3kB

仅显示镜像 ID

-q 选项可仅显示本地所有镜像的 ImageID。该主要是将来与其它命令联合使用。

[root@docker ~]# docker images -q
9c7a54a9a43c
36c607e7b14d

过滤镜像

-f 选项用于过滤指定条件的镜像。下面例举一些常用的过滤条件。例如,

[root@docker ~]# docker images -f dangling=true
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

dangling=true 用于过滤出悬虚镜像,即没有 Repository 与 Tag 的镜像。对于悬虚镜像的REPOSITORY 与 TAG,显示的是。

-f before 用于列举出本地镜像中指定镜像创建时间之前创建的所有镜像。

[root@docker ~]# docker images -f before=nginx
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
zookeeper    latest    36c607e7b14d   19 months ago   278MB

-f since 用于列举出本地镜像中指定镜像创建时间之后的创建的所有镜像。

[root@docker ~]# docker images -f since=nginx
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    9c7a54a9a43c   2 months ago   13.3kB
s

-f reference 用于列举出:与指定表达式相匹配的所有镜像。

注意只查官方的

[root@docker ~]# docker images -f reference=*:latest
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    9c7a54a9a43c   2 months ago    13.3kB
nginx         latest    605c77e624dd   18 months ago   141MB
zookeeper     latest    36c607e7b14d   19 months ago   278MB

[root@docker ~]# docker images -f reference=nginx:*
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        latest    605c77e624dd   18 months ago   141MB
s
[root@docker ~]# docker images -f reference=*n*
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        latest    605c77e624dd   18 months ago   141MB

格式化显示

该选项用于格式化输出 docker images 的内容,格式需要使用 GO 模板指定。

[root@docker ~]# docker images --format {{.Tag}}
latest
latest
latest

[root@docker ~]# docker images --format {{.Repository}}:{{.Tag}}
hello-world:latest
nginx:latest
zookeeper:latest

问题:

为什么是 {{.Repository}}:{{.Tag}} 不是{{images.Tag}}获取吗?

在 Docker 命令行中,docker images 命令用于列出本地主机上的 Docker 镜像。当你使用 --format 参数来指定输出格式时,可以使用 Go 语言模板风格来自定义输出。在你提供的命令中,{{.Repository}}:{{.Tag}} 是一个 Go 模板,用于将镜像的仓库(Repository)和标签(Tag)以特定的格式输出。

Docker 镜像有多个属性,包括 RepositoryTagID 等,Go 模板允许你从这些属性中提取信息并进行格式化输出。

回答你的问题:images.Tag 不是合法的 Go 模板表达式。在 Go 模板中,{{.Tag}} 表示获取镜像的标签属性,而 {{.Repository}} 表示获取镜像的仓库属性。这样的表达式可以用来自定义输出格式,将镜像的仓库和标签以 “仓库名:标签” 的格式输出。

例如,对于以下命令输出:

REPOSITORY         TAG
hello-world       latest
nginx             latest
zookeeper         latest

如果你使用了 docker images --format "{{.Repository}}:{{.Tag}}",它会将仓库和标签以 “仓库名:标签” 的格式输出,结果如下:

hello-world:latest
nginx:latest
zookeeper:latest

这样输出的结果更加简洁和易读,而不再包含表头等其他信息。

search

介绍

docker search 是一个 Docker 命令,用于在 Docker Hub 或其他容器注册表中搜索镜像。它允许你根据关键字查找特定的镜像,并获取有关这些镜像的基本信息。下面是 docker search 命令的详细介绍:

语法:

docker search [OPTIONS] TERM

参数:

  • OPTIONS: 可选参数,用于进一步定制搜索结果的输出。
  • TERM: 必选参数,表示搜索的关键字或镜像名。

使用示例:

docker search nginx
docker search --limit 5 ubuntu

说明:

  • 当你运行 docker search 命令时,Docker 将查询 Docker Hub 或默认的容器注册表来搜索与给定关键字(TERM)相关的镜像。如果你未指定特定的容器注册表地址,它会默认搜索 Docker Hub 上的镜像。

  • 搜索结果将包含一系列匹配关键字的镜像列表,并按相关性排序,最相关的镜像将显示在前面。

  • 输出结果包含以下信息:

    • NAME:镜像名称,通常以仓库名和标签组合而成。
    • DESCRIPTION:镜像的简要描述。
    • STARS:Docker Hub 用户给予该镜像的星标数量,表示其受欢迎程度。
    • OFFICIAL:如果镜像是 Docker 官方镜像,则显示为 “OK”;否则,显示为空。
    • AUTOMATED:如果镜像是通过自动构建而来(Automated Build),则显示为 “OK”;否则,显示为空。
  • 你可以使用一些可选参数来进一步定制搜索结果:

    • --limit N:限制返回的搜索结果数量为 N 个。
    • --filter "is-official=true":仅返回官方镜像。
    • --filter "is-automated=true":仅返回自动构建镜像。
    • --filter "stars=N":仅返回星标数量为 N 的镜像。
  • 如果你要搜索不同的容器注册表,可以通过在 docker search 命令后面添加容器注册表地址来指定。例如:

    docker search registry.example.com/nginx
    
  • 注意,Docker 官方的搜索镜像功能已于2021年1月1日停用。现在,搜索功能由第三方容器注册表提供。

例子

[root@docker ~]# docker search --help

Usage:  docker search [OPTIONS] TERM

Search 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
      --no-trunc        Don't truncate output

[root@docker ~]# docker search nginx 
NAME                                              DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                         18768     [OK]       
unit                                              Official build of NGINX Unit: Universal Web …   6         [OK]       
nginxproxy/nginx-proxy                            Automated Nginx reverse proxy for docker con…   92                   
nginxproxy/acme-companion                         Automated ACME SSL certificate generation fo…   116                  
bitnami/nginx                                     Bitnami nginx Docker Image                       168                  [OK]
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   29                   [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   96                   
nginxproxy/docker-gen                             Generate files from docker container meta-da…   12                   
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in…   6                    
rancher/nginx-ingress-controller                                                                   11                   
rancher/nginx-ingress-controller-defaultbackend                                                    2                    
bitnami/nginx-exporter                                                                             5                    
rancher/nginx                                                                                      2                    
rapidfort/nginx-ib                                RapidFort optimized, hardened image for NGIN…   10                   
rapidfort/nginx                                   RapidFort optimized, hardened image for NGINX    14                   
vmware/nginx-photon                                                                                1                    
rapidfort/nginx-official                          RapidFort optimized, hardened image for NGIN…   10                   
nginxproxy/forego                                 Foreman in Go                                    0                    
vmware/nginx                                                                                       2                    
rancher/nginx-conf                                                                                 0                    
bitnamicharts/nginx                                                                                0                    
linuxserver/nginx                                 An Nginx container, brought to you by LinuxS…   204                  
privatebin/nginx-fpm-alpine                       PrivateBin running on an Nginx, php-fpm & Al…   77                   [OK]
elestio/nginx-auto-ssl                            The simpliest solution to add SSL cert to yo…   0                    
rancher/nginx-ssl                                                                                  0                    

AUTOMATED 表示当前镜像是否是“自动化镜像”。什么是自动化镜像?就是使用 Docker Hub 连接一个包含 Dockerfile 文件(专门构建镜像用的文件)的 GitHub 仓库或 Bitbucket 仓库的源码托管平台,然后 Docker Hub 就会自动根据 Dockerfile 内容构建镜像。这种构建出的镜像会被标记为 AUTOMATED,这种构建镜像的方式称为 Trusted Build(受信构建)。只要 Dockerfile文件内容发生变化,那么 Docker Hub 就会构建出新的镜像。

用于过滤查询结果。例如,下面的是仅查询出官方提供的镜像。

[root@docker ~]# docker search -f is-official=true nginx
NAME      DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx     Official build of Nginx.                         18768     [OK]       
unit      Official build of NGINX Unit: Universal Web …   6         [OK]   

返回 Docker Hub 中星标数量为 100 的 nginx 镜像列表

[root@docker ~]# docker search -f stars=100 nginx
NAME                        DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                       Official build of Nginx.                         18768     [OK]       
nginxproxy/acme-companion   Automated ACME SSL certificate generation fo…   116                  
bitnami/nginx               Bitnami nginx Docker Image                       168                  [OK]
linuxserver/nginx           An Nginx container, brought to you by LinuxS…   204                  

限制检索数量

通过–limit 选项来指定显示的结果数量。

[root@docker ~]# docker search nginx --limit=2
NAME      DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx     Official build of Nginx.                         18768     [OK]       
unit      Official build of NGINX Unit: Universal Web …   6         [OK]     

格式化

[root@docker ~]# docker search --format '{{json .}}' nginx
[root@docker ~]# docker search --format {{.Name}} nginx
nginx
unit
nginxproxy/nginx-proxy
nginxproxy/acme-companion
bitnami/nginx
bitnami/nginx-ingress-controller
ubuntu/nginx
nginxproxy/docker-gen

rmi

介绍

docker rmi 是 Docker 命令行工具用于删除本地主机上的一个或多个 Docker 镜像的命令。“rmi” 代表 “remove image”,它允许你清理不再需要的 Docker 镜像,以释放磁盘空间或管理镜像版本。

以下是 docker rmi 命令的详细介绍:

用法:

docker rmi [OPTIONS] IMAGE [IMAGE...]

参数:

  • OPTIONS: 可选参数,用于指定不同的选项。常见的选项包括:

    • -f, --force: 强制删除镜像,即使有容器正在使用该镜像。
    • --no-prune: 不删除镜像的过程中不移除未被标记的父镜像。
    • --filter: 根据指定的条件来筛选要删除的镜像。
    • 等等,你可以通过 docker rmi --help 查看完整的选项列表。
  • IMAGE: 要删除的 Docker 镜像名称或镜像ID。可以同时指定多个镜像,用空格隔开。

示例:

  1. 删除单个镜像:

    docker rmi my_image:latest
    
  2. 删除多个镜像:

    docker rmi image1:tag1 image2:tag2
    
  3. 强制删除正在使用的镜像:

    docker rmi -f my_image:latest
    
  4. 删除所有未被使用的镜像:

    docker image prune
    

注意事项:

  • 如果要删除的镜像正在被一个或多个容器使用,通常会出现错误。除非使用 -f, --force 参数来强制删除,否则 Docker 不会删除正在使用的镜像。
  • 被删除的镜像无法恢复,因此在使用 docker rmi 命令时要小心,确保你不再需要这些镜像。

在使用 docker rmi 命令时,请务必谨慎处理,确保你清楚哪些镜像是可以安全删除的,以避免误删重要的镜像或数据。

例子

[root@docker ~]# docker rmi --help

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Aliases:
  docker image rm, docker image remove, docker rmi

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents

[root@docker ~]# docker rmi nginx
...
[root@docker ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    9c7a54a9a43c   2 months ago    13.3kB
zookeeper     latest    36c607e7b14d   19 months ago   278MB

docker rmi 也可通过 ImageID 指定要删除的镜像。

docker rmi 9c7a54a9a43c

强制删除镜像

默认情况下,对于已经运行了容器的镜像是不能删除的,必须要先停止并删除了相关容器然后才能删除其对应的镜像。不过,也可以通过添加-f 选项进行强制删除。

docker rmi -f  9c7a54a9a43c

删除所有镜像

使用组合命令删除所有镜像。当然,如果不携带-f 选项,则不会删除已打开容器的镜像

docker rmi -f ${docker images -q}

docker images -q显示所有的镜像的id

导出导入镜像

save

[root@docker ~]# docker save --help

Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Aliases:
  docker image save, docker save

Options:
  -o, --output string   Write to a file, instead of STDOUT

导出指定镜像

[root@docker ~]# docker save -o my.tar zookeeper  nginx
[root@docker ~]# ll
总用量 337348
-rw-------. 1 root root      1244 7月  15 11:35 anaconda-ks.cfg
-rw-------  1 root root 345440256 7月  19 11:27 my.tar

[root@docker ~]# docker save  zookeeper  nginx >my1.tar
[root@docker ~]# ll
总用量 674692
-rw-------. 1 root root      1244 7月  15 11:35 anaconda-ks.cfg
-rw-r--r--  1 root root 345440256 7月  19 11:28 my1.tar
-rw-------  1 root root 345440256 7月  19 11:27 my.tar
 

load

[root@docker ~]# docker load --help

Usage:  docker load [OPTIONS]

Load an image from a tar archive or STDIN

Aliases:
  docker image load, docker load

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

恢复

[root@docker ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    9c7a54a9a43c   2 months ago   13.3kB
[root@docker ~]# docker load -i my.tar

-qi和-q -i 都可以 -i需要接后面指定删除的镜像.不能反过来

[root@docker ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    9c7a54a9a43c   2 months ago    13.3kB
nginx         latest    605c77e624dd   18 months ago   141MB
zookeeper     3.7       36c607e7b14d   19 months ago   278MB
zookeeper     latest    36c607e7b14d   19 months ago   278MB

用提前下载好的my.tar load 还原镜像

[root@docker ~]# docker load <my.tar

docker load 用于从 Docker 存档文件中(通常是由 docker save 命令生成的)恢复镜像和容器的内容。并还原成完整的镜像。可以包含多个镜像和标签。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哈密猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值