docker image save
描述 | 將一個或多個映象儲存到 tar 歸檔檔案(預設流式傳輸到 STDOUT) |
---|---|
用法 | docker image save [OPTIONS] IMAGE [IMAGE...] |
別名 | docker save |
描述
生成一個 tar 格式的倉庫到標準輸出流。包含所有父層、所有標籤 + 版本,或為每個提供的引數指定 `repo:tag`。
選項
選項 | 預設值 | 描述 |
---|---|---|
-o, --output | 寫入檔案,而不是 STDOUT | |
--platform | API 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/amd64
或 linux/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