Docker is the most commonly used tool for generating and handling containers that are individual environments for running software applications. To create and execute these portable containers, Docker images are used. A Docker image holds all the necessary files for executing an app and a container’s runtime instance of the Docker image.
This blog will discuss:
- What is Docker Saving and Loading Images?
- How to Save Images in Docker?
- How to Load Images in Docker?
What is Docker Saving and Loading Images?
As we discussed above, images are used to build the containers for executing the software applications. Sometimes, developers need to store the Docker images and containers for backup. For that purpose, the “docker save” command is used. Docker users can also restore images from backup, generate custom images from scratch, and share custom images with other users by loading the images. To do so, the “docker load” command is used.
How to Save Images in Docker?
Let’s have a look at the below-described instructions to save the Docker image:
- Launch the Docker Desktop application.
- Open the Windows PowerShell terminal and run the “docker login” command.
- List images and select one of them.
- Execute the “docker save <image-name> -o <output-file>” command.
- Use the “ls <output-file>” command for verification.
Step 1: Open Docker Desktop
First of all, launch the Docker Desktop application using the Start menu:
As a result, the Docker Desktop application will start:
Step 2: Docker Login
Then, open your preferred terminal, login with Docker by running the docker login command:
Step 3: List Docker Images
To display all the Docker images, execute the provided command:
From the appeared output, we have selected the demo1 Docker image for further use:
You can also use the following command to list all existing Docker images:
Step 4: Save Image in Docker
Finally, use the below-given command to save the Docker image:
- docker save command is utilized for saving the image to the tar archive file.
- demo1 is our existing Docker image name that we need to save.
- -o option is used for specifying the output file.
- Newdemo1.tar is our output file name:
Step 5: Verification
Now, run the following command to check if the particular Docker image has been stored as a file or not:
How to Load Images in Docker?
To load the images on Docker, execute the provided command along with the i option for specifying the input file, and newdemo1.tar is the archive file name where a particular image needs to be loaded:
It can be seen that; the specified image has been uploaded successfully:
Then, run the below-given command to list all the images for verification whether the image has been loaded or not:
According to the provided output, the demo1 exist in the image list:
That’s it! We have compiled a detailed process for saving and loading images on Docker.
Docker images contain instructions that help the container while running. For that purpose, users first need to save images on Docker and then load them. To save an image on Docker, the docker save <image> -o <output-file> command is used. While, for loading images on Docker, the docker load -i <output-file> command is used. This blog demonstrated the easiest way to save and load images on Docker.