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.
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.
[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
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 exportubuntu-web | gzip > ubuntu-web.tar.gz
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
7 Comments
hi
[email protected]:~# docker run -i -t klokantech/openmaptiles-server /bin/bash
[email protected]:/#
change [email protected]*** and how to hosting countainer???
If u want to change [email protected] then u can specify with command #docker run -it –hostname=anything-here repositorynamehere(ex:-ubuntu:latest) /bin/bash
Hi
I use docker run -d -p 63700:80 –name apachetest –volumes-from apache3 apache , and export to tar file.
When I import to different server , I lost all of settings , how do I backup the container parameter?
thanks.
docker run -it -d yourrepo or anything else u want to attach with command at last dont forget to use command
# docker commit your repositorynamehere
This worked ok, but not all of the data has moved with the container.
Do you have any further notes on how to copy underlying data?
Have you attached any data volume to the container?