How to export and import Docker containers

For whatever reason, you don’t want to use any docker registry or repository to commit your changes and push/pull images and also you want to keep the current state and data in your containers. You need to use export/import commands of docker.

export your container

sudo docker export name_of_container > exported_file.tar

copy your exported and compressed file to your new server or pc and then

import it like this

cat exported_file.tar | sudo docker import - image_name:your_tag

run your newly imported image into container

sudo docker run -itd --name container_name image_name:your_tag /bin/bash