Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

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 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 using docker 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

CommandDescription
docker load -i my_image.tarLoad a Docker image from a tar file
`cat my_image.tardocker load`
`gunzip < my_image.tar.gzdocker load`
docker load --input backup.tarLoad an image using the --input option
docker load -i multiple_images.tarLoad multiple images from a tarball
docker load -i image.tar --quietLoad an image without verbose output

Best Practices for Using docker load:

  1. Verify the image tarball before loading it to ensure it was created properly (docker save).
  2. Compress tarballs with gzip or xz to reduce file size for easier transfer.
  3. Use meaningful filenames (e.g., my_app_backup_20250207.tar) for better organization.
  4. Automate image loading in scripts to streamline CI/CD processes.
  5. Check the loaded image with docker images to confirm successful import.

Common Errors and Solutions

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

Combining docker load with Other Commands

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

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

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x