Docker load command

Docker command reference


docker loadThe command is used fromdocker saveLoad Docker images from the tar file generated by the command. It can load the images and all layers from the archive into Docker, making them available for use in new environments.

Syntax

docker load [OPTIONS]

OPTIONS description:

  • -i, --inputSpecify the path to the input file.
  • -q, --quietQuiet mode, reduce output information.

1. Load image from file

docker load -i myimage.tar

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

2. Load image from standard input

cat myimage.tar | docker load

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

Example

1. Build and save image

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

# 使用 Ubuntu 作为基础镜像
FROM ubuntu:20.04

# 添加维护者信息
LABEL maintainer="[email protected]"

# 更新包列表并安装 Nginx
RUN apt-get update && apt-get install -y nginx

# 复制自定义网页到 Nginx 的默认网页目录
COPY index.html /var/www/html/

# 设置启动时的默认命令
CMD ["nginx", "-g", "daemon off;"]

Build image:


docker build -t mynginx:latest .

Save image to file:

docker save -o mynginx.tar mynginx:latest

2. Load image

Load image from file:

docker load -i mynginx.tar

3. Verify the loaded image

docker images

Output example:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mynginx             latest              123abc456def        1 minute ago        200MB

Notes

  • The loaded image includes all its layers and metadata, exactly matching its state at the time of saving.
  • Usagedocker loadWhen doing so, all images contained in the tar file will be loaded.
  • The loading process may take a long time, depending on the size of the image and system performance.

docker loadThe command is a convenient way to restore Docker images from a saved tar file. By combiningdocker saveanddocker loadusers can easily back up, distribute, and migrate Docker images across different environments.


Docker command reference

other extensions