How to Copy/Move Docker Images and Export/Import Docker Containers between hosts
In this post, we’ll show you how to copy/move a docker image between hosts and import/export a docker container between hosts. You may need to do this move images/containers between dev team to save time downloading Docker image from your private repository or save time consumed in adding your configuration to a running container.
This tutorial divided into two parts. Part 1: will help you to export and import Docker images and move them between hosts. Part 2: will help you to export and import Docker containers and move them between hosts. Let’s start:
Part 1: Copy/Move Docker Images between Hosts
Step 1: List Docker Images
Fist list docker images on your system using below command.
# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos latest 2933d50b9f77 11 days ago 196.6 MB ubuntu latest 36248ae4a9ac 11 days ago 188 MB
Step 2: Save or Archive Image
Now use the following command to save image repository named ubuntu (image id: 36248ae4a9ac) and make a zipped archive named ubuntu-latest.tar.gz. Remember that save is used for making backup of docker images (not containers).
# docker save ubuntu | gzip > ubuntu-latest.tar.gz
Step 3: Import Image
After saving docker image in archive format on your system move it to remote system using scp or ftp. After that use below command on remote system to import Docker image with name ubuntu and tag name latest.
# zcat ubuntu-latest.gz | docker import - ubuntu:latest
The above command will create a docker image with name ubuntu and tag name latest on your system. You can now launch containers using this image like below.
# docker run -i -t ubuntu /bin/bash
Part 2: Export and Import Docker Containers between Hosts
Step 1: 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.
# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours ubuntu-web 2b199b9976c4 centos "/bin/bash" 3 days ago Up 3 hours centos-mysql
Step 2: Export Container
Finally use the following command to export container named ubuntu-web (container id: f2582758af13) and make a zipped archive named ubuntu-web.tar.gz. Remember that export is used for making backup of docker containers (not images) in image format.
# docker export ubuntu-web | gzip > ubuntu-web.tar.gz
Step 3: Import Container
After exporting docker container on your system move it to remote server using scp or ftp. After that use below command on remote server to import Docker container on remote server with name ubuntu-web.
# zcat ubuntu-web.gz | docker import - ubuntu-web
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 ubuntu-web /bin/bash
If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donate
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.