What is the difference between save and export in Docker?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When working with Docker, you'll often come across the need to save or export images and containers. Although these terms might seem interchangeable at first glance, they actually refer to different operations with distinct use cases. Understanding the difference between "save" and "export" in Docker is crucial for effectively managing Docker images and containers.
Docker Basics: Images and Containers
Before diving into the differences between saving and exporting, it's important to clarify what Docker images and containers are:
- Docker Image: A lightweight, standalone, and executable package that includes everything needed to run a piece of software. It comprises the application code, libraries, environment variables, and runtime requirements.
- Docker Container: An instance of a Docker image. When an image is run, it becomes a container, offering an isolated environment to execute applications.
Save vs. Export: Understanding the Differences
Docker save
The docker save command is used primarily for exporting Docker images. It packages the image and all associated layers into a tarball (.tar file). This command is particularly useful when you need to transfer an image between different Docker engines or environments that cannot access the Docker registry.
Technical Explanation
- Command Syntax:
- What It Includes:
- Image layers
- Image metadata, such as labels and history
- Essential information to reconstruct the same image in another environment
- Usage Scenario:
- Useful for backup purposes
- Transferring images to a system without direct access to the Docker registry
Docker export
In contrast, the docker export command is used for exporting Docker containers. When you export a container, it strips away the image layers and only captures the filesystem of the container’s current state into a tarball. This does not include the image metadata and thereby is more lightweight but less comprehensive compared to docker save.
Technical Explanation
- Command Syntax:
- What It Includes:
- The filesystem contents of the container
- Running state of the container at the time of export (without metadata)
- Usage Scenario:
- Migrating a container's filesystem to another environment where you want to restore the state
- Creating a snapshot of the current container state
Key Differences: save vs. export
The table below summarizes the key differences between docker save and docker export:
| Criterion | docker save | docker export |
| Target | Docker Images | Docker Containers |
| Includes | Image layers, Metadata | Filesystem snapshot |
| State Captured | Original state at image creation | Current state of the container |
| Registry | Suitable for environments without registry access | More lightweight and state-specific |
| Use Case | Backup/Transfer full image details | Migrate or snapshot filesystem state |
| Command for Usage | docker save -o <file.tar> <image> | docker export -o <file.tar> <container> |
Additional Considerations
When deciding between docker save and docker export, consider the following:
- Reconstruction Efficiency: If you use
docker save, the restoration process (docker load) retains the image with all its layers and metadata, making deployment on new systems straightforward. However, withdocker export, you'll need to create a new image manually from the filesystem snapshot usingdocker import. - Complexity and Overhead:
docker saveproduces larger files because it retains all image layers and metadata. In contrast,docker exportresults in smaller files, but you lose the capability to rebuild the image exactly as the original. - Portability and Flexibility: For environments where the Docker Hub is not accessible,
docker saveis invaluable. However, if you are interested in capturing and transferring only the changes done after the container started,docker exportis the right choice.
Conclusion
In summary, docker save is intended for backing up and sharing Docker images along with their metadata, providing you an exact replica of the original image. On the other hand, docker export focuses on the state of a running container, capturing only the filesystem and omitting layers and metadata. Choosing the appropriate command depends on your specific needs in terms of transferring, backing up, or deploying Docker assets. Understanding these distinctions will help you tailor your Docker management strategy effectively.
Related reading
- What is the difference between subPath and mountPath in Kubernetes
- What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?
- What is the difference between the size and the virtual size of the docker images?
- what is the difference between vagrant, docker, virtualenv or just a virtual machine?
- What is the difference between scalability and elasticity?
- What is the difference between the core os projects kube-prometheus and prometheus operator?
- What is the different between openshift deploymentconfig and kubernetes deployment
- What is the Docker Subnet used for?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.