How to Convert a Docker Image to a TAR File (Step-by-Step)
Export Docker images as .tar files for backups, offline transfers, or air-gapped deployments.
What you'll need
- Docker installed on your system (Docker Desktop for Windows/macOS, Docker Engine on Linux)
- An image available locally (use
docker images
to list images)
Step 1 — Identify the image
List local images and note the REPOSITORY:TAG you want to export:
docker images
Example output:
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 22.04 2b4f4a6a4a82 2 weeks ago 77MB
Step 2 — Save the Docker image as a .tar
Use docker save
and the -o
flag to write a tar file:
docker save -o ubuntu_22.04.tar ubuntu:22.04
Notes:
- The
-o
flag specifies the output file. You can also use redirection:docker save ubuntu:22.04 > ubuntu_22.04.tar
- You can save multiple images into one tar:
docker save -o my_images.tar image1:tag image2:tag
Step 3 — Verify the .tar file
Check your current directory for the generated tar file:
Windows (PowerShell):
Get-ChildItem
macOS / Linux:
ls -lh
Step 4 — Load the TAR file on another system
Import the saved image with docker load
:
docker load -i ubuntu_22.04.tar
Expected output:
Loaded image: ubuntu:22.04
Optional — Compress the TAR to save space
Compress the tar to gzip:
tar -czvf ubuntu_22.04.tar.gz ubuntu_22.04.tar
Load directly from gzipped stream without creating intermediate tar on the target:
gunzip -c ubuntu_22.04.tar.gz | docker load
Quick commands reference
Action | Command |
---|---|
Save image to tar | docker save -o image.tar image:tag |
Load image from tar | docker load -i image.tar |
Compress tar | tar -czvf image.tar.gz image.tar |
Load from gzip stream | gunzip -c image.tar.gz | docker load |
Troubleshooting tips
- If you get permission errors when saving or loading, try running the command in an elevated shell (Administrator / root) or ensure Docker is running.
- Large images may take time — compressing helps for transfers but requires extra CPU/time to compress/decompress.
- For private registry images, ensure you
docker login
first if you intend to push the same image later to a registry.
Post a Comment