vengadesh
vengadesh

Reputation: 21

How to save entire Docker content into tar file?

I tried to install a Ubuntu machine using the Docker command

docker run -it --name mymachine ubuntu

In that Ubuntu machine, I have installed the following applications

  1. Java
  2. Unzip
  3. SSH

And then I performed Docker commit operation docker commit mymachine copymachine. Now if I run this copy image in a new container means it working perfectly. But in my case, I'm trying to save that image file using the "save" command:

docker save copymachine > MachineInfo.tar

And then forwarding this tar file to my another machine and trying to load this image in that Docker using the following command

docker load MachineInfo.tar updatedmachine

If I try to run this image in a container and trying to access the application installed on the previous machine container.

But none of the applications were been showing in the newly created container.

Upvotes: 1

Views: 6395

Answers (1)

Amit Meena
Amit Meena

Reputation: 4444

Inlined with @ halfer comment, You need to perform simple export and import. Please perform the following steps.

  1. Start the container
docker run -it --name mymachine ubuntu /bin/bash
  1. Update and install the jdk
apt update
apt install default-jre
  1. Validate that java is up and accessible
java -version
  1. Export the image to tar from another command line. First, do a docker ps and note down the container id of the container in which you have installed java, lets say it is 4719ab149ee2. Export the container into a tar using the command.
docker export 4719ab149ee2  > mymachine.tar
  1. Stop the container.
docker stop <container_id>
  1. Remove the ubuntu image from your local registry by executing the following commands.
docker images
dokcer image rm <image_id>
  1. Now import the image from the tar file using the command.
C:\Users\ameena>docker import - mymachine <  mymachine.tar
  1. Now check that image has been imported into your local registry by executing the command.
docker images
  1. Now create a container from this image using the command.
docker run -it --name mymachinefromimage mymachine:latest /bin/bash
  1. Now check that java is present by using the command.
java --version

Note: Step 5,6,7,8,9 are validation steps.

Upvotes: 3

Related Questions