Overview of Docker Export and how to implement it.

Overview of Docker Export and how to implement it.
Written by Nilima PaulFebruary 16, 2022
10 min read
Nilima Paul

Technology Security Analyst

The purpose of this blog post is to discuss Docker export. It will show you how Docker export works, how to implement it, and what the advantages are.

Brief description of Docker export:

The docker export command does not export the contents of volumes associated with the container. If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume.

Refer to Backup, restore, or migrate data volumes in the user guide for examples on exporting data in a volume.


docker export [OPTIONS] container


-o, –output – It is a string type and used to write the output to a file, instead of STDOUT.


docker export --help

Explanation: We use ‘–help’ to know all about the ‘docker export’ as shown above. We can see that this command has only one option ‘-o’ for redirecting the output to a file.

How does export work in Docker:

It takes something like one contention that is a holder name or compartment ID. Whenever we run this order it saves the holder's record framework as a file. It makes a level Docker picture that makes the Docker picture marginally more modest in size, in any case, it lost its set of experiences and metadata which implies we can't play out any rollback to a past layer assuming we import a Docker picture utilizing any sent out tar document.

The following is a depiction of an envelope construction of a sent out compartment:


tree -L 1 alpine-export

Explanation: We export a Docker container in a tar file and extracted the tar file in a folder ‘alpine-export’. The above example is the tree structure of that folder.

Example to implement Docker export:

Below are the examples:

Scenario 1: Update any File of the Docker Image.

We have assembled n Nginx Docker Image and a compartment is running utilizing this Docker picture anyway when we peruse the web application, we understood that something missing on the landing page. We want to refresh the landing page and make another Docker picture however assembling the picture without any preparation utilizing Dockerfile will take additional time so we will roll out the improvements in the index.html record when the compartment is running and we trade the holder and afterward import it as a Docker picture. So we should get everything rolling:

1. Below is the snippet of Dockerfile and index.html files:

  • index.html:


<!DOCTYPE html>
<title>Docker Export</title>
<h1>Example of Docker export</h1>
  • Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get install -y nginx
add index.html /var/www/html
CMD ["nginx", "-g", "daemon off;"]

2. Build the docker image named ‘my-Nginx' using below command:

docker build -t my-Nginx

3. Run a container using the above Docker image as below:

docker run -d -p 80:80 my-Nginx

4. Now, let’s assume that we got a requirement to change the background color of the heading ‘Example of Docker Export’ to blue, so we will update the index.html file in the running container and export it as an archive using the below command:


sudo docker exec -it 44 sh

Replace the line “<h1>Example of Docker export</h1>” with below line in the index.html file as shown in the snapshot:

<h1 style="background-color:DodgerBlue;">Example of Docker export</h1>

5. Export the running container after making the changes using the below command and import it as a Docker image named ‘my-Nginx:v2’;


docker export 44 > my-nginx.tar
docker import -c ‘CMD [“nginx”, “-g”, “daemon off;”]’ my-nginx.tar my-nginx:v2
docker run -d -p 8081:80 my-nginx:v2

Explanation: Run a new container using the imported Docker file to verify the changes are successfully applied as expected and when we browse the default page, we can see that the background color of the heading has been changed to blue in the below image.

Scenario 2: Create a Single Layer Docker Image

When we create a Docker image it has multiple layers as each instruction in a Dockerfile creates a layer while building the image. If we want to create a single layer Docker image to enhance the performance of the container, we export the container and import it as a Docker image as shown in the below steps:

1. Check the layers of any Docker image using the below Command:


docker image history <image_name>


docker image history my-Nginx

2. Now, again run a container using this image and export it as an archive:


docker run -d -p 80:80 --name Nginx-container my-Nginx
docker export Nginx-container > my-nginx.tar

3. Import the exported archive file or tar file with the command and message as below and check the history of the newly imported Docker image:


docker import -c 'CMD ["nginx", "-g", "daemon off;"]' -m "single layer Docker image" my-nginx.tar my-nginx:v3
docker image history my-nginx:v3

Explanation: In the above snapshot, we can see that there is only one layer showing after importing the exported archive. It helps to improve the performance, however, it is not recommended by Docker as Docker encourages building a multilayer Docker image to use the cache function of the image building process.

Advantages of Docker export:
  1. Speed: Docker export is quicker than re-fabricating the Docker picture if any minor changes are required.
  2. Picture Sharing: As we probably are aware to share the Docker picture we want to push it to a vault, notwithstanding, we can utilize Docker commodity to send out it as a chronicle and we can impart it to others like we share documents.
  3. Execution: When we import the sent-out document utilizing Docker import it makes a solitary layer Docker picture that works on the exhibition of the holder.

Docker trade is an order line instrument to send out any compartment as a file and chronicle contains a standard Linux filesystem with all the holder information aside from information of mounted volumes. docker commodity and docker import the two orders generally cooperate.

Docker Export
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