Docker Community Forums

Share and learn in the Docker community.

How to preserve image layers id's when saving image to .tar

I need to save docker image to .tar and next load it back.
When I run a sequence of instructions like below, I lose the id’s of the layers. Is there a workaround for this problem?

docker history image:tag
IMAGE CREATED CREATED BY SIZE COMMENT
54546f0a854c 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
dda93d59693b 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B
da3e1f934e6b 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B
516f3cb58fe8 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 112MB
d34e802cb96e 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
efcb826c05ed 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
a84241a912e1 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B

docker save image:tag > image.tar
docker prune system -a
docker load -i image.tar
docker history image:tag
IMAGE CREATED CREATED BY SIZE COMMENT
ff32a624edc4 12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 112MB
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0B
12 minutes ago xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 122B