Files
nexus/wiki/concepts/Docker-Save.md
2026-04-21 16:03:27 +08:00

77 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Docker Save
type: concept
tags: [docker, container, image-transfer]
last_updated: 2026-04-21
---
# Docker Save
## Definition
`docker save` 是 Docker CLI 命令,用于将一个或多个镜像导出为 tar 归档文件(`.tar`),实现镜像的离线存储和传输。
## Syntax
```bash
docker save [OPTIONS] IMAGE [IMAGE...]
```
### Options
| Option | Description |
|--------|-------------|
| `-o, --output` | 指定输出文件名(默认输出到 stdout |
## Usage Examples
### 基本用法
```bash
# 导出单个镜像
docker save -o nginx.tar nginx:latest
# 导出多个镜像
docker save -o images.tar nginx:latest redis:alpine postgres:15
# 使用管道传输
docker save nginx:latest | ssh user@remote-host 'docker load'
```
### 典型工作流:将镜像从开发机传输到 NAS
```bash
# 在开发机上
docker save -o xiaoya.tar xiaoyaliu/alist:latest
# 将 xiaoya.tar 复制到 NAS通过 SMB/SCP
scp xiaoya.tar nas:/volume1/docker/images/
# 在 NAS 上
docker load < xiaoya.tar
```
## Related Concepts
- [[Docker-Load]]:对应的导入命令
- [[Docker-Image]]:被导出的对象
- [[Docker-TAR-Archive]]:生成的归档文件格式
## Relationships
- [[Docker-Image]] ← 导出为 ← [[Docker-Save]]
- [[Docker-Save]] → 输出 → [[Docker-TAR-Archive]]
## Key Points
1. **保留镜像层**:完整保留镜像的分层结构
2. **保留元数据**:包括 CMD、ENTRYPOINT、ENV、LABEL 等
3. **可移植性**:生成的 tar 文件可在任何 Docker 环境中导入
4. **适用场景**:离线环境迁移、备份、镜像分发
## Notes
- 文件大小可能较大(包含所有镜像层)
- 多次 save 同一镜像会重复包含所有层
- 可配合 `docker load` 实现完整的镜像迁移闭环