Docker load command
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:
-i, --input: Specify the path of the input file.-q, --quiet: Quiet mode, reducing output information.
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
- The loaded image includes all its layers and metadata, exactly as it was when saved.
- Use
docker loadWhen this command is used, all images contained in the tar file are loaded. - The loading process may take a long time, depending on the image size and system performance.
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 Reference