What is Docker Import and how can we import image?

What is Docker Import and how can we import  image?
Written by Nilima PaulFebruary 16, 2022
12 min read
Nilima Paul

Technology Security Analyst

The objective of this article is to learn how to Import Docker image and why it's so useful.

Introduction to Docker Import:

Docker import is a Docker order to make a Docker picture by bringing in the substance from a document or tarball which is made by sending out a holder. We can indicate URL or '-' to import information or content from the document. The URL can highlight where chronicle record is available and '-' (run) is utilized to import information straightforwardly from the STDIN for example standard information. We can apply Dockerfile guidelines while making the picture utilizing Docker import anyway there are restricted Dockerfile directions that are upheld here.


docker import [options] file|URL|- [REPOSITORY[:TAG]]


  1. -c, –change: It is used to provide Dockerfile instructions if needed while creating the Docker image. It takes input as a list.
  2. -m, –message: It is used to add a message to the Docker image while importing from an archive file. It is a string.

Here is the snapshot of the ‘docker import –help’ output that tells what we just discussed above.

How to Import Docker Image:

To import a Docker picture, first, we should have a traded document record of a holder. So when we trade any compartment, it sends out holders as a customary Linux document framework in a chronicle record; then, at that point, we need to import this file document as a Docker picture and when we run any compartment utilizing this new imported Docker picture then it works similarly as it was working in the old holder. This saves our opportunity to construct the Docker picture without any preparation on the off chance that there are any progressions are required. Docker import just backings these Dockerfile directions: CMD, ENTRYPOINT, ENV, EXPOSE, ONBUILD, USER, VOLUME, WORKDIR.


Let’s understand the process using an example:

Example #1 – Exporting a Container

1. First, create a Docker image using the below Dockerfile:

docker build -t my-image:v2.

2. Run this image as a container using the below command: –

docker run my-image:v2
docker ps –a

3. Export the container in a tar file named helloworld.tar using the below command: –


docker export <container_ID> > <file_name>
docker export <container_name> > <file_name>


docker export 3673f8996e1a > helloworld.tar


In the above snapshot, we have created a Docker image named ‘my-image:v2’ and started a container using it, and the container just displayed output “Hello World!!!” that is mentioned in the Docker image and it gets stopped. Then, we have exported this container as a tar file named “helloworld.tar”.

Example #2 – Investigating the Exported Archive File

4. Now create a folder ‘HelloWorld’ and extract the content of the tar file to this folder as below: –

mkdir HelloWorld
tar -xf helloworld.tar -C HelloWorld

5. And if we check the folder structure of HelloWorld, it looks like a regular Linux filesystem.

tree –L 1 HelloWorld

Example #3 – Different Ways to Import the Docker Image

6. Let’s import this tar file as a Docker image using the below command: –


docker import <archive_name> <Image_name>
cat <archive_name> | docker import - <image_name>


docker import helloworld.tar my-imported-img:v1
cat helloworld.tar | docker import – my-imported-img:v2

docker import history my-imported-IMG:v1


In the above snapshot, we will see there is no difference in the images so we can use any of the above commands to import the Docker image from an archive.

7. We can also pass comments while importing the Docker image using the ‘-m’ option as below: –


cat <archive_name> | docker import -m <comment or message> - <image_name>


cat helloworld.tar | docker import -m “New Image imported” – my-imported-image:v3

Example #4 – Verify the Imported Image

8. Run a container using this new Docker image to verify if it is working as the earlier container:

docker run --it my-imported-img:v1 sh


In the above example, we can see that we need to specify the command while running a container using the imported Docker image as there is no command to run so we get an error if we run the command.

docker run my-imported-IMG:v1

Example #5 – Adding Dockerfile instruction while importing the Image

9. We can apply Dockerfile instruction while importing the Docker image using the ‘-ca' option as below: –


docker -c <Dockerfile Instruction> <archive_file> <image_name>


docker -c ‘CMD echo “HelloWOrld!!!”’ helloworld.tar my-imported-img:v4

10. Presently, suppose we need to add a record to the last picture. We can do this in two ways, the first is to alter the Dockerfile and modify the picture or run a compartment utilizing this picture and make the document and product the holder and afterward import it as another Docker picture. The simple way is to run a holder and roll out the expected improvements and product it and import it as a Docker picture.

docker run -it my-image:v1 sh


In the above example, created a new container using the ‘my-image:v1’ and connected to it; created a testfile.txt and populated some data in it. Exported that container and imported as a Docker image named ‘my-imported-IMG:v5’ and ran a new container using this newly imported image and when we can see that the ‘testfile.txt’ exists in this container as well.

  1. It is exceptionally helpful assuming that we need to roll out minor improvements to the current picture yet don't have any desire to reconstruct the Docker picture as it requires some investment to revamp without any preparation once more. It saves our time by staying away from the modified cycle of the picture also.
  2. We can share the Docker pictures with others without involving the Docker library as we can send out it as a tar record and offer the tar as we share ordinary documents and one can import it utilizing Docker import.
  3. It is additionally helpful to make a solitary layer Docker picture record that is now and again expected to work on the presentation, and so on, in any case, it isn't suggested by Docker.
docker image history my-image:v1
docker image history my-imported-IMG:v5


In the above snapshot, we can see that the ‘my-image:v1’ image has 3 layers however the imported image ‘my-imported-IMG:v5’ has only one layer.


Docker Import is an incredible instrument that assists us with saving time by keeping away from the re-construct interaction of Docker picture for minor changes and further the Docker picture with others without Docker library, notwithstanding, we have 'burden' and 'save' order to reinforcement or offer the Docker picture. It just works with the compartment. We generally utilize this to work on the exhibition of the compartment as it makes a solitary layer Docker picture.

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