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 load a Docker image from a tarball (image archive file) into the local Docker image repository. It is commonly used for importing images that were saved with the docker save command.
Key Features:
- Restores Docker images from a tar archive.
- Useful for transferring images between systems without using a Docker registry.
- Supports compressed and uncompressed tar files.
Basic Syntax
docker load [OPTIONS]
Code language: CSS (css)
Options:
-i,--input: Specify the file to load the image from (instead of standard input).--quiet: Suppress the verbose output during the image 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 the tarball my_image.tar into the local Docker repository.
2. Load an Image from a Compressed Tarball
gunzip < my_image.tar.gz | docker load
This decompresses my_image.tar.gz and loads the image into Docker.
3. Load an Image Using Standard Input
cat my_image.tar | docker load
This pipes the tarball content directly into docker load.
4. Load Multiple Images from a Single Tarball
docker load -i multiple_images.tar
Code language: CSS (css)
If the tarball contains multiple images, docker load will restore all of them.
5. Use docker load in a Script for Automation
#!/bin/bash
for tarfile in /backup/images/*.tar; do
docker load -i $tarfile
echo "Loaded image from $tarfile"
done
Code language: JavaScript (javascript)
This script loads all tar files from the /backup/images directory into Docker.
6. Load an Image Quietly (Suppress Output)
docker load --input my_image.tar --quiet
Code language: CSS (css)
This loads the image without showing verbose output.
7. Load an Image with Docker Compose
You can combine docker load with docker-compose in your CI/CD pipeline:
services:
web:
image: my_image:latest
build:
context: .
hooks:
post_build:
- docker load -i my_image.tar
Code language: CSS (css)
Use Cases for docker load
1. Image Transfer Between Environments
- Transfer Docker images between development, testing, and production environments without pushing them to a registry.
- Example: Move a large image from a build server to production.
2. Backup and Restore Docker Images
- Save images with
docker saveand restore them later usingdocker load. - Example: Backup custom application images before upgrading Docker or the host system.
3. Air-Gapped Environments
- Use
docker loadto transfer images in air-gapped networks where internet access is restricted. - Example: Deliver a set of images to a secure environment without using Docker Hub.
4. Disaster Recovery
- Load previously saved images as part of a disaster recovery plan.
5. CI/CD Pipelines
- Use
docker loadin CI/CD pipelines to preload images on build agents. - Example: Preload common base images to speed up builds.
6. Sharing Custom Images
- Share custom-built images with teams or clients by sending the image tarball.
List of Common docker load Commands
| Command | Description |
|---|---|
docker load -i my_image.tar | Load a Docker image from a tar file |
| `cat my_image.tar | docker load` |
| `gunzip < my_image.tar.gz | docker load` |
docker load --input backup.tar | Load an image using the --input option |
docker load -i multiple_images.tar | Load multiple images from a tarball |
docker load -i image.tar --quiet | Load an image without verbose output |
Best Practices for Using docker load:
- Verify the image tarball before loading it to ensure it was created properly (
docker save). - Compress tarballs with
gziporxzto reduce file size for easier transfer. - Use meaningful filenames (e.g.,
my_app_backup_20260207.tar) for better organization. - Automate image loading in scripts to streamline CI/CD processes.
- Check the loaded image with
docker imagesto confirm successful import.
Common Errors and Solutions
- “No such file or directory”
โ Ensure the tarball exists and the file path is correct. - “Invalid tar file”
โ Verify that the tarball was created withdocker saveand is not corrupted. - “Image not found after loading”
โ Check the output ofdocker loadto ensure the image was loaded with the expected tag. - “Permission denied”
โ Run the command withsudoor check file permissions.
Combining docker load with Other Commands
Backup and Restore Workflow
- Save the image:
docker save -o my_image.tar my_image:latest - Transfer and load the image:
docker load -i my_image.tar
Verify the Loaded Image
docker images | grep my_image
Automate Image Loading in a CI/CD Pipeline
steps:
- name: Load Prebuilt Docker Image
run: docker load -i my_prebuilt_image.tar
Code language: CSS (css)
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.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals