In our previous tutorials you have learned about installation of Docker engine on CentOS/RHEL and Ubuntu operating system and pulled images from Docker hub. After that created containers with images. This tutorial will help you to export and import Docker containers and move them between hosts.
Fist list all containers on your system using below command. Using ps -a will list all containers (running and stopped) from your system.
[email protected]:~# 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
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
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