YouTip LogoYouTip

Docker Save Command

# Docker save Command [![Image 3: Docker Command Manual](#)Docker Command Manual](#) * * * The `docker save` 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 IMAGE [IMAGE...] * **`IMAGE`**: One or more image names or IDs to save. OPTIONS Description: * **`-o, --output`**: Specify the path of the output file. 1. Save a single image to a file docker save -o myimage.tar myimage:latest This saves the `myimage:latest` image as the `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. ## Examples ### Build a Sample Image 1. 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's default web directory COPY index.html /var/www/html/# Set 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 the `mynginx.tar` file. 3. Verify the saved file ls -lh mynginx.tar Output example: -rw-r--r-- 1 user user 200M Jul 24 14:00 mynginx.tar 4. Load the saved image To load the saved image into another Docker environment, you can use the `docker load` command: docker load -i mynginx.tar ### Notes * When saving an image, all layers of the image are included, so the resulting tar file may be large. * If multiple images are saved to the same file, using the `docker load` command will load all included images. * To reduce file size, you can use the `docker image prune` command before saving to clean up unused images and layers. The `docker save` command is a convenient tool for saving Docker images as tar files, facilitating backup, distribution, and migration. By combining it with the `docker load` command, you can easily restore and use saved images in different environments. * * Docker Command Manual](#)
← Docker ResourcesDocker Rmi Command β†’