Introduction
Docker images package applications and their dependencies into a portable format. For example, you can save a Docker image as a file for backup, storage, or transfer between different environments.
Docker provides the docker save command to create a TAR archive from a Docker image. As a result, you can store the TAR file for future use.
In this guide, we will explain how to save a Docker image as a TAR file and verify the generated archive.
Prerequisites
Before you begin, make sure you have the following:
- Docker is installed on the server.
- The Docker service is running.
- You have the required permissions to run Docker commands.
- The Docker image that you want to save is available on the server.
- Make sure you have enough disk space to create the TAR file.
IMPLEMENTATION
Step 1: Identify the Docker Image
First, list the available Docker images with the following command:
docker images
Example:

Step 2: Save the Docker Image as a TAR File
Next, use the docker save command to create a TAR file from the Docker image:
For example, the following command saves the alpine:latest image as mynewimage.tar
docker save -o mynewimage.tar alpine:latest
Here:
docker savecreates an archive of the Docker image.-o mynewimage.tarspecifies the name of the output TAR file.alpine:latestSpecifies the Docker image that you want to save.
Step 3: Verify the TAR File
After that, check whether Docker created the TAR file successfully:
ls -lh mynewimage.tar

Step 4: Compress the TAR File (Optional)
If the TAR file is large, you can compress it with gzip to reduce its size:
gzip mynewimage.tar
This creates:
mynewimage.tar.gz
Alternatively, you can save and compress the Docker image directly:
docker save alpine:latest | gzip > myapp.tar.gz

Conclusion
Saving a Docker image as a TAR file provides a simple way to create a portable copy of the image. The docker save command creates the TAR archive, which you can store as a backup or use for other Docker image management tasks.
By following these steps, you can easily save a Docker image as a TAR file and verify the generated archive.
FAQ
Can we compress a Docker TAR file?
Yes. You can use gzip to compress the TAR file and create a .tar.gz file.
How can I restore a Docker image from a TAR file?
You can use the docker load command to import the Docker image from the TAR file. For example:
docker load -i mynewimage.tar
Can we save multiple Docker images in one TAR file?
Yes. The docker save command allows you to save multiple Docker images into a single TAR file.
docker save -o images.tar alpine:latest nginx:latest
Related Articles
How to Convert a Docker Container into a Docker Image
Talk to our experts:
Looking for the right technology solution for your business?. Our experts can help with web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team here.