MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker commands Guide – docker save with examples

Hereโ€™s a complete tutorial on docker save and docker load, covering what they do, examples, and use cases.


What are docker save and docker load?

  • docker save: This command exports Docker images (with all layers, tags, and metadata) as a tarball file. You can then transfer or archive the image.
  • docker load: This command restores images from a tarball created with docker save.

Key Features:

  • docker save: Backup and transfer images without relying on a Docker registry.
  • docker load: Import images from tarballs on any machine.
  • Supports compressed tarballs (.tar.gz).

docker save Command Syntax

docker save [OPTIONS] IMAGE [IMAGE...]
Code language: CSS (css)

Options:

  • -o, --output: Write the tarball to a file instead of standard output.

Examples of docker save

1. Save a Single Image to a Tarball

docker save -o my_image.tar my_image:latest
Code language: CSS (css)

This saves the my_image:latest to a tar file named my_image.tar.


2. Save Multiple Images to a Single Tarball

docker save -o images_backup.tar my_image:latest alpine:3.14 nginx:latest
Code language: CSS (css)

This saves multiple images (my_image, alpine, and nginx) to a single tar file.


3. Save an Image and Compress It

docker save my_image:latest | gzip > my_image.tar.gz

This saves the image and compresses it into my_image.tar.gz.


4. Use docker save with Standard Output

docker save my_image:latest > my_image.tar
Code language: CSS (css)

This saves the image and writes the output to a tar file.


5. Save and Transfer an Image to Another System

docker save -o my_image.tar my_image:latest
scp my_image.tar user@remote:/path/to/destination
Code language: JavaScript (javascript)

This saves the image to my_image.tar and transfers it to a remote machine using scp.


6. Automate Image Backup with a Script

#!/bin/bash
docker save -o /backups/my_app_$(date +%Y%m%d).tar my_app:latest
echo "Image backed up as my_app_$(date +%Y%m%d).tar"
Code language: JavaScript (javascript)

This script saves my_app:latest with a timestamped filename.


7. Check the Content of a Saved Tarball

tar -tvf my_image.tar
Code language: CSS (css)

This lists the contents of the tar file, showing layers and metadata.


docker load Command Syntax

docker load [OPTIONS]
Code language: CSS (css)

Options:

  • -i, --input: Load from a file instead of standard input.
  • --quiet: Suppress verbose output during the load process.

Examples of docker load

1. Load an Image from a Tarball

docker load -i my_image.tar
Code language: CSS (css)

This loads the image from my_image.tar into the local Docker repository.


2. Load a Compressed Tarball

gunzip < my_image.tar.gz | docker load

This decompresses my_image.tar.gz and loads the image.


3. Load an Image from Standard Input

cat my_image.tar | docker load

This pipes the tar file into docker load.


4. Load Multiple Images from a Single Tarball

docker load -i images_backup.tar
Code language: CSS (css)

If images_backup.tar contains multiple images, they will all be loaded into Docker.


5. Quietly Load an Image

docker load -i my_image.tar --quiet
Code language: CSS (css)

Suppresses verbose output while loading the image.


6. Automate Image Loading with a Script

#!/bin/bash
for tarfile in /backup/images/*.tar; do
  docker load -i $tarfile
  echo "Loaded image from $tarfile"
done
Code language: JavaScript (javascript)

Use Cases for docker save and docker load

1. Backup and Restore Images

  • Backup images to tar files for disaster recovery.
  • Restore images after a system upgrade or failure.
  • Example: Save a production image and reload it on a fresh Docker host.

2. Transfer Images Between Systems

  • Move images between development, staging, and production environments without pushing them to Docker Hub.
  • Example: Transfer images to an air-gapped environment.

3. CI/CD Pipelines

  • Preload common images on build agents for faster builds.
  • Example: Use docker save to cache images and docker load to reuse them in CI/CD.

4. Air-Gapped Deployments

  • Use docker save to transfer images into restricted environments without internet access.
  • Example: Load images into an offline server.

5. Sharing Custom Images

  • Share custom-built Docker images with clients or collaborators as tar files.
  • Example: Send a custom application image as my_app.tar.gz.

6. Disaster Recovery and Migration

  • Use docker save to migrate images to a new host.
  • Example: Move legacy Docker images to a new infrastructure.

List of Common docker save and docker load Commands

CommandDescription
docker save -o my_image.tar my_image:latestSave an image to a tar file
`docker save my_image:latestgzip > my_image.tar.gz`
docker save -o images_backup.tar nginx alpineSave multiple images to a single tarball
docker load -i my_image.tarLoad an image from a tar file
`gunzip < my_image.tar.gzdocker load`
docker load < my_image.tarLoad an image using standard input
docker save -o backup.tar my_app:1.0Save a specific image tag

Best Practices for Using docker save and docker load:

  1. Use meaningful filenames when saving images (e.g., my_app_backup_20260207.tar).
  2. Compress large images with gzip or xz to reduce file size.
  3. Verify the loaded image with docker images to ensure it imported successfully.
  4. Automate image backups in scripts for regular snapshots.
  5. Check tarball integrity before loading (tar -tvf my_image.tar).

Common Errors and Solutions

  1. “No such file or directory”
    โ†’ Ensure the tar file exists and the path is correct.
  2. “Invalid tar file”
    โ†’ Verify the tarball was created with docker save and is not corrupted.
  3. “Image not found after loading”
    โ†’ Check the output of docker load to confirm the image and tag.
  4. “Permission denied”
    โ†’ Run the command with sudo or check your user permissions.

Combining docker save and docker load in Workflows

Backup and Restore Workflow

  1. Save the image: docker save -o my_image.tar my_image:latest
  2. Transfer and load the image: docker load -i my_image.tar

Automate Backup and Restore

#!/bin/bash
# Backup
docker save -o /backups/my_app_backup.tar my_app:latest

# Restore
docker load -i /backups/my_app_backup.tar
Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Install Sonatype Nexus with Docker: RM2/RM3 Commands, Validation Steps, and Important Caveats

A structured, production-minded rewrite of the original 2016 Docker setup for Sonatype Nexus Repository Manager 2 and 3. Includes command examples, a workflow diagram, and clear warnings about outdated tags/endpoints.

Read More

Docker Lab & Assignment – Creating an Image

Hereโ€™s a detailed Tutorial and Lab Guide for the listed Docker commands, focused on practical usage, explanations, and step-by-step labs with Ubuntu + git + apache2 as…

Read More

Docker commands Guide – docker tag with examples

Hereโ€™s a complete tutorial on docker tag, covering what it does, examples, and use cases. What is docker tag? docker tag is a Docker command that creates…

Read More

Docker commands Guide – docker rmi with examples

Hereโ€™s a complete tutorial on docker rmi, including what it does, examples, and use cases. What is docker rmi? docker rmi is a Docker command used to…

Read More

Docker commands Guide – docker load with examples

Hereโ€™s a complete tutorial on docker load, covering what it does, examples, and use cases. What is docker load? docker load is a Docker command used to…

Read More

Docker commands Guide – docker import with examples

Hereโ€™s a complete tutorial on docker import, covering what it does, examples, and use cases. What is docker import? docker import is a Docker command that creates…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x