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]
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
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
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
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
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
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 save
and restore them later usingdocker load
. - Example: Backup custom application images before upgrading Docker or the host system.
3. Air-Gapped Environments
- Use
docker load
to 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 load
in 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
gzip
orxz
to reduce file size for easier transfer. - Use meaningful filenames (e.g.,
my_app_backup_20250207.tar
) for better organization. - Automate image loading in scripts to streamline CI/CD processes.
- Check the loaded image with
docker images
to 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 save
and is not corrupted. - “Image not found after loading”
→ Check the output ofdocker load
to ensure the image was loaded with the expected tag. - “Permission denied”
→ Run the command withsudo
or 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
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND