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

Docker save Command

Docker save Command

Docker Command ReferenceDocker Command Reference


docker save The command is used to save one or more Docker images to a tar archive file for distribution or backup in other environments.

Syntax

docker save [OPTIONS] IMAGE [IMAGE...]

OPTIONS description:

1. Save a single image to a file

docker save -o myimage.tar myimage:latest

This saves the myimage:latest image as a myimage.tar file.

2. Save multiple images to the same file



docker save -o multiple_images.tar myimage:latest anotherimage:latest

This saves the myimage:latest and anotherimage:latest images to the multiple_images.tar file.

Example

Build a sample image

1. Create a Dockerfile:

# 使用 Ubuntu 作为基础镜像

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 .

2. Save the image to a file



docker save -o mynginx.tar mynginx:latest

This saves the mynginx:latest image as a mynginx.tar file.

3. Verify the saved file



ls -lh mynginx.tar

Example output:



-rw-r--r-- 1 user user 200M Jul 24 14:00 mynginx.tar

4. Load the saved image

To load a saved image into another Docker environment, you can use the docker load command:



docker load -i mynginx.tar

Notes

docker save The command is a convenient tool for saving Docker images to tar files for backup, distribution, and migration. By combining it with docker load you can easily restore and use saved images in different environments.


Docker Command ReferenceDocker Command Reference