Save function in Docker | How its works and its benefits

Save function in Docker | How its works and its benefits
Written by Nilima PaulFebruary 19, 2022
8 min read
Nilima Paul

Technology Security Analyst

We will discuss about the save function in Docker.

Introduction of Docker save function:

The 'Docker save function' is utilized to save at least one than one picture to a tar file. It incorporates all parent layers, and all labels or forms. It is as a matter of course gushed to STDOUT, notwithstanding, we can keep in touch with a record, rather than STDOUT by determining a banner. This order is extremely helpful when we need to utilize Docker pictures on various machines without utilizing a library or archive. We can likewise pack or save the picture to a tar.gz document utilizing gzip.

How to save function works in Docker:

As far as we might be concerned, is utilized to save Docker pictures to a chronicle. Whenever we run this order from the order line, the Docker daemon saves the referenced Docker picture as a file. We can then import that file to various groups or various PCs, etc. Presently, we react to stack that file document, to utilize that picture. At the point when we load that file document once more, it makes a Docker picture.


Let’s understand the whole process with an example.

Scenario: We are going to save a Docker image and then will load it after deleting the existing image.

Step 1. Let’s check available Docker images locally using the below command:
docker image ls

Explanation: In the above depiction, we can see that there are two pictures accessible, we should take the 'ubuntu' Docker picture with the 'most recent tag. On the off chance that the picture isn't accessible locally, pull it from the public library that is utilizing the beneath order:

docker pull ubuntu
Note: We can use any Docker images; they should be available locally.

Step 2. Now, we have a Docker image available locally let’s save it to an archive file as shown below:
docker save ubuntu -o my-ubuntu.tar
ls my-ubuntu2.tar

Explanation: In the above preview, we can see that the '- o' choice has been utilized to save it to a chronicle and the name of the file is 'my-ubuntu.tar'. We can likewise utilize redirection rather than the '- o' choice to divert the result to a file document as displayed underneath:

docker save ubuntu > my-ubuntu2.tar
ls my-ubuntu2.tar
Step 3. Let’s verify by deleting the exiting image and loading it from the archive using the below command:

docker image rm ubuntu
docker image ls
docker load –I my-ubuntu.tar
docker image ls

Explanation: In the above preview, we have erased the 'ubuntu' picture that we have confirmed utilizing the subsequent order and afterward we have stacked the picture utilizing the document record in which we have saved the picture before. We need to utilize the '- I' choice to teach the Docker daemon to stack the picture from a chronicle document rather than STDOUT. At last, we have taken a look at the locally accessible pictures to confirm and we can see that the picture is accessible once more.

Scenario: Save multiple images at once.

Step 1. Let’s save two Docker images Ubuntu and Nginx to an archive file as shown below:

docker save -o my-images.tar ubuntu nginx: alpine
Step 2. Let’s verify it as well using the same way we did earlier:

docker image rm ubuntu nginx: alpine
docker image ls
docker load -o my-images.tar
docker image ls

Explanation: As per the above example, we can understand that we can save multiple images in a single archive, so we load it again, it will load all the images that were saved using the ‘Docker save’ command.

Scenario: Save Docker images to a tar.gz file.

Solution: We can do it by using the gzip command. It compresses the tar and makes it smaller in size. We can run the below command to save the images to a tar.gz file:

docker save IMAGE [IMAGE] | gzip > <archive_name.gz>
docker save ubuntu nginx: alpine | gzip > my-images2.tar.gz
ll my-images.tar my-images2.tar.gz

Explanation: In the above snapshot, we can see that the ‘my-images2.tar.gz’ file is much smaller than the ‘my-images.tar’ file.

Benefits of Docker save:
  1. The principal advantage is we can share Docker pictures with our groups or test on various PCs without utilizing the Docker vault.
  2. We can document the Docker pictures on the off chance that not being used, for instance, old forms are not needed after another form is delivered, nonetheless, we need to save it for quite a while pribeforeiminating it so better we can file those pictures.
  3. We can save a great deal of circle space assuming that we additionally pack the document utilizing gzip.

The 'Docker save function' is a convenient order to save the pictures just, it doesn't save changes made to the picture by any running holder utilizing that picture. We have another order to save the pictures and that is 'Docker picture save'. This order works in much the same way as the 'Docker save' order.

Docker Save
Docker secrets
Docker swarm
Was this blog helpful?
You must be Logged in to comment
Code Block

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance