Thursday, November 21, 2024
HomeDevOpsHow to save and import/export docker images

How to save and import/export docker images

For now we installed and play with some docker commends like how to pull and run images and container. Now will see how to save and import docker images from one host to another. Also here will discuss how to import and export a docker images.

List Docker Images

Now will check the images we have in docker,

[root@foxutech ~]# docker images

docker images

Save and compress Image

To save an image we need to use #docker save, and for now will save Centos (image id: 970633036444) image and compress into MyCentOS.tar.gz.

[root@foxutech ~]# docker save centos | gzip > MyCentOS.tar.gz

Note: Save is used for making backup of docker images (not containers).

Import Image

Once we saved and compress the Image into zip format, now we can move a zip file via either FTP or SCP. Once we moved/copied to remote host, we can import using following commend.

[root@foxutech ~]# zcat MyCentOS.tar.gz | docker import – centos:latest

Here, latest is tagname and Centos is docker image name

The above command will create a docker image with name centos and tag name latest on your system. You can now launch containers using this image like below.

[root@foxutech ~]# docker run -i -t centos /bin/bash

List Containers

Fist list all containers on your system using below command. Using ps -a will list all containers (running and stopped) from your system.

[root@foxutech ~]# docker ps –a 

CONTAINER ID   IMAGE   COMMAND     CREATED       STATUS     PORTS NAMES

1c0c4d8fa497   ubuntu   “/bin/bash” 8 hours ago   Up 1 hours         container8

9f6331703a21   centos   “/bin/bash” 4 days ago   Up 2 hours     container16

Export Container

Below commend will export a Ubuntu image (image ID: 1c0c4d8fa497) and compress that too zip format.

# docker export container8 | gzip > container8.tar.gz

Import Container

Once we exported and compress the Image into zip format, now we can move a zip file via either FTP or SCP. Once we moved/copied to remote host, we can import using following commend

# zcat container8.tar.gz | docker import – container8

sha256:ca982185a9591b130798a5739597c05c04c28f273fe6294a7b5c663e3f26d61e

The above command will create a docker image on your system. You can now launch a container from this image using below command.

# docker run -i -t container8 /bin/bash

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments