Docker

What is Docker Saving and Loading Images

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?

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:

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:

docker login

Step 3: List Docker Images

To display all the Docker images, execute the provided command:

docker images

From the appeared output, we have selected the demo1 Docker image for further use:

OR

You can also use the following command to list all existing Docker images:

docker image ls

Step 4: Save Image in Docker

Finally, use the below-given command to save the Docker image:

docker save demo1 -o newdemo1.tar

Here:

  • 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:

ls newdemo1.tar

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:

docker load -i newdemo1.tar

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:

docker images

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.

Conclusion

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.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.