Docker_Import_Export

Docker_Import_Export

Import and Export Docker image

If we have any configured container and we want to save all changes(commit) in Docker image we use theses process.
Also, we can export these image and run container with help of these image, in a different machine.  

 

First check “CONTAINER ID” which you want to import using below command.

[root@rhel7 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              7 hours ago         Up 7 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 8 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Commit all changes of a container which make Docker image.

Here “feenix_web” is name of Docker image and “c92a3e450ca1” is container ID.

[root@rhel7 ~]# docker commit c92a3e450ca1 feenix_web
sha256:b91f1f0109001b6e94db3d0c439136232736d88732db301b93184196bacac725

After commit we have all changes save in new Docker image(Apache + PHP + WordPress setting.. etc)

 

Check new Docker image created or not.

[root@rhel7 ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
feenix_web                              latest              b91f1f010900        3 minutes ago       338.8 MB

 

Save Docker image as TAR or export to other Docker VM.

In this example, I’m going to save docker image in /tmp

[root@rhel7 ~]# docker save -o /tmp/feenix_web.tar feenix_web
[root@rhel7 ~]# ll /tmp/
total 340732
-rw——-. 1 root root 348898304 Oct 30 19:16 feenix_web.tar
 

Now copy this Docker image TAR file to other machine and start the container.

 

For example, you copy these image in /tmp location on another machine.

Note:- Docker must be installed in a machine(VM).

[root@rhel7 ~]# docker load < /tmp/ feenix_web.tar

Now list Docker image
[root@rhel7 ~]# docker images
Docker image listed with ”feenix_web

Now start container with ”feenix_web” docker image.

[root@rhel7 ~]# docker run -it –name ubuntu_apache -p 82:80 feenix_web

 

Leave a Reply

Your email address will not be published. Required fields are marked *