Docker

Can I Save Docker Image as File?

A Docker image is a lightweight, standalone, executable package that has all the necessary instructions needed to execute the software. It is the snapshot of the Docker container, which is running the instance of an image. Docker images can be created locally or users can download them from Docker Hub. Moreover, users can also save the Docker images as a file to keep the backup or offline development.

This write-up will discuss about saving a Docker Image as a file.

Can I Save Docker Image as a File?

Yes, the Docker image can be saved as a file. To do this, utilize the “docker save <image-name> -o <output-file-name>” command.

Step 1: List Docker Images

First, display all the available Docker images and choose the desired image that needs to be saved as a file:

docker image ls

 

In the below output, all the Docker images can be seen and we have selected the “alpine” image:

Step 2: Save Image as a File

Then, utilize the below-listed command to save the desired image as a file:

docker save alpine -o my-alpine.tar

 

Here:

  • docker save” command is utilized to save the Docker image to the tar archive file.
  • alpine” is the Docker image that needs to be saved as a file.
  • -o” is utilized to specify the output file.
  • my-alpine.tar” is the output file name:

Step 3: Verify Changes

Now, ensure that the Docker image has been saved as a file or not using the following command:

ls my-alpine.tar

 

The below screenshot indicates that the Docker image has been saved as a tar archive file:

Alternatively, users can use the “docker save <image-name> > <output-file-name>” command to save the Docker image as a file.

Step 1: Save Docker Image

First, execute the below-listed command to save the particular Docker image as a file:

docker save alpine > my-alpine2.tar

 

Here, the “docker save” command is utilized to save the “alpine” Docker image to the “my-alpine2.tar” archive file:

Step 2: Ensure Changes

Then, verify whether the Docker image has been saved as a file or not:

ls my-alpine2.tar

 

It can be observed that the Docker image has been saved as a tar archive file:

Bonus Tip: Verification

Lastly, follow the provided path in your PC to view the tar archive files:

C:\Users\<user-name>

 

As you can see, the Docker image has been saved as a tar archive files, i.e., “my-alpine” and “my-alpine2”:

That was all about saving the Docker image as a file.

Conclusion

Docker allows users to save the Docker image as an archive file. To do this, first, choose the desired Docker image that needs to be saved as a file. Then, utilize the “docker save <image-name> -o <output-file-name>” or “docker save <image-name> > <output-file-name>” command. Lastly, verify changes using the “ls <output-file-name>” command. This write-up explained the method of saving a Docker Image as a file.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.