How to Export & Import Docker Image

Contents
We can always pull docker images from docker registry. But, sometimes we need to share our images manually. In this post, I will share you how to import and export docker images.
Export Docker Image
Let say we have these two docker images in my local docker
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 547b3c3c15a9 4 weeks ago 501MB
postgres 12 d480c196f9b0 3 months ago 405MBWe want to export postgres docker image. To do that, we can do that using docker export command like this :
$ docker export postgres > postgres.tarHere are the explanation for this command. In general the command is like this :
$ docker export <image-name> > <output-name>.tar- change
<image-name>with the image that you want to export - change
<output-name>in to the output name you intended. The output file will be on.tarformat.
Import Docker Image
Let say you want to import / load the exported docker image file (the .tar file). You can use docker load command like this :
$ docker load -i postgres.tarIn general, the command is like this :
$ docker load -i <tar-file>.tarIf the import / load is successful, you will see the image if you run docker images command.
That’s all, very simple :)
External sources :
ahmadtheswe blog