Backup / Export Docker containers to other hosts

Source Host
———–
Commit the current container

docker commit <name or ID of the container instance> my_container_image

Save the container

docker save my_container_image | gzip > my_container_image.tar.gz

Copy the image and container to the destination host (e.g., cp, scp or rsync).

 

Destination Host
—————-
Load the container

gunzip -c my_container_image.tar.gz | docker load

or

docker load -i mycontainer.tgz

— example —

$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3c18f283964d odoo:12.0 "/entrypoint.sh odoo" 6 weeks ago Up 12 days 8071-8072/tcp, 0.0.0.0:8012->8069/tcp odoo12
bed0248e1e48 postgres:10 "docker-entrypoint.s…" 6 weeks ago Up 12 days 0.0.0.0:5433->5432/tcp db12
298fc144c4d9 odoo "/entrypoint.sh odoo" 3 months ago Up 12 days 8071-8072/tcp, 0.0.0.0:8014->8069/tcp odoo14
3f1a829d8f69 postgres:10 "docker-entrypoint.s…" 3 months ago Up 12 days 5432/tcp db
# commit
sudo docker commit db 15web_pgsql:170521
sudo docker commit odoo14 15web:170521
sudo docker commit db12 15collab_pgsql:170521
sudo docker commit odoo12 15collab:170521
# save
sudo docker save 15web_pgsql:170521 | gzip > 15web_pgsql_170521_1245.tar.gz
sudo docker save 15web:170521 | gzip > 15web_170521_1245.tar.gz
sudo docker save 15collab_pgsql:170521 | gzip > 15collab_pgsql_170521_1245.tar.gz
sudo docker save 15collab:170521 | gzip > 15collab_170521_1245.tar.gz
# remove images
sudo docker rmi 15web_pgsql:170521
sudo docker rmi 15web:170521
sudo docker rmi 15collab_pgsql:170521
sudo docker rmi 15collab:170521
# load image
sudo docker load -i 15web_pgsql_170521_1245.tar.gz
sudo docker load -i 15web_170521_1245.tar.gz
sudo docker load -i 15collab_pgsql_170521_1245.tar.gz
sudo docker load -i 15collab_170521_1245.tar.gz