Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker load command

Docker load command

Docker Command ReferenceDocker Command Reference


docker load The command is used to load Docker images from a tar file generated by the docker save command. It can load the images and all their layers from the archive into Docker, making them usable in a new environment.

Syntax

docker load [OPTIONS]

OPTIONS description:

1. Load an image from a file



docker load -i myimage.tar

This will load the image from the myimage.tar file.

2. Load an image from standard input



cat myimage.tar | docker load

This will load the image from standard input through a pipe.

Example

1. Build and save an image

First, build and save a sample image; create a Dockerfile:



# Use Ubuntu as the base image

FROM ubuntu:20.04



# Add maintainer information

LABEL maintainer="yourname@example.com"



# Update package list and install Nginx

RUN apt-get update && apt-get install -y nginx



# Copy custom webpage to Nginx default webpage directory

COPY index.html /var/www/html/



# Set the default command on startup

CMD ["nginx", "-g", "daemon off;"]

Build the image:





docker build -t mynginx:latest .

Save the image to a file:



docker save -o mynginx.tar mynginx:latest

2. Load the image

Load the image from a file:



docker load -i mynginx.tar

3. Verify the loaded image



docker images

Example output:



REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

mynginx             latest              123abc456def        1 minute ago        200MB

Notes

docker load The command is a convenient way to restore Docker images from a saved tar file. By combining it with docker save, docker save and docker loadusers can easily back up, distribute, and migrate Docker images across different environments.


Docker Command ReferenceDocker Command Reference