docker image save

描述将一个或多个镜像保存为 tar 归档文件(默认输出到 STDOUT)
用法docker image save [OPTIONS] IMAGE [IMAGE...]
别名
docker save

描述

将一个打包好的仓库输出到标准输出流。包含所有父层、所有标签 + 版本,或每个提供的参数指定的 repo:tag

选项

选项默认值描述
-o, --output写入文件,而不是 STDOUT
--platformAPI 1.48+ 仅保存指定的平台变体。格式为 os[/arch[/variant]](例如,linux/amd64

示例

创建一个备份,后续可以使用 docker load 加载。

$ docker save busybox > busybox.tar

$ ls -sh busybox.tar

2.7M busybox.tar

$ docker save --output busybox.tar busybox

$ ls -sh busybox.tar

2.7M busybox.tar

$ docker save -o fedora-all.tar fedora

$ docker save -o fedora-latest.tar fedora:latest

使用 gzip 将镜像保存为 tar.gz 文件

可以使用 gzip 保存镜像文件,使备份更小。

$ docker save myimage:latest | gzip > myimage_latest.tar.gz

挑选特定标签

甚至可以挑选镜像仓库的特定标签。

$ docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy

保存特定平台 (--platform)

`--platform` 选项允许您指定要保存的镜像的平台变体。默认情况下,docker save 保存守护进程镜像存储中存在的所有平台变体。使用 `--platform` 选项指定要保存的镜像的平台变体。如果指定的平台在本地镜像存储中不存在,则会产生错误。

平台选项采用 os[/arch[/variant]] 格式;例如,linux/amd64linux/arm64/v8。体系结构和变体是可选的,如果省略,则默认为守护进程的原生体系结构。

以下示例拉取 alpine:latest 镜像的 RISC-V 变体并将其保存到 tar 归档文件中。

$ docker pull --platform=linux/riscv64 alpine:latest
latest: Pulling from library/alpine
8c4a05189a5f: Download complete
Digest: sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

$ docker image save --platform=linux/riscv64 -o alpine-riscv.tar alpine:latest

$ ls -lh image.tar
-rw-------  1 thajeztah  staff   3.9M Oct  7 11:06 alpine-riscv.tar

以下示例尝试保存本地镜像存储中不存在的 alpine:latest 镜像平台变体,从而导致错误。

$ docker image ls --tree
IMAGE                   ID             DISK USAGE   CONTENT SIZE   IN USE
alpine:latest           beefdbd8a1da       10.6MB         3.37MB
├─ linux/riscv64        80cde017a105       10.6MB         3.37MB
├─ linux/amd64          33735bd63cf8           0B             0B
├─ linux/arm/v6         50f635c8b04d           0B             0B
├─ linux/arm/v7         f2f82d424957           0B             0B
├─ linux/arm64/v8       9cee2b382fe2           0B             0B
├─ linux/386            b3e87f642f5c           0B             0B
├─ linux/ppc64le        c7a6800e3dc5           0B             0B
└─ linux/s390x          2b5b26e09ca2           0B             0B

$ docker image save --platform=linux/s390x -o alpine-s390x.tar alpine:latest
Error response from daemon: no suitable export target found for platform linux/s390x