Docker load and save: "archive/tar: invalid tar header" Docker load and save: "archive/tar: invalid tar header" linux linux

Docker load and save: "archive/tar: invalid tar header"


I wanted to add that the issue probably occurs because of the difference in behaviour of STDOUT between Windows and Unix. Therefore, using the STDOUT way of saving like:

docker save [image] > file.tar followed by docker load < file.tar

will not work if the save and load are executed on a different OS. Always use:

docker save [image] -o file.tar followed by docker load -i file.tar

to prevent these issues. Comparing the TAR files produced by the different methods, you will find that they have a completely different size (303MB against 614MB for me).


As a more detailed description to Ostecke's answer.

I've found it's not a windows specific issue. It's a powershell issue. Powershell emits two byte characters to STDOUT, not one byte characters. If you look in the file you'll notice that the TAR header has nulls between what should be the correct header (and in the rest of the file). This explains why the file is twice the size.

CMD on the other hand does not emit multibyte characters to STDOUT. I've found the STDOUT method of saving a file works fine across different OSes if you use CMD on windows.

Using powershell, only the -o option is safe:

docker save [image] -o file.tar

Using CMD, either method should work fine.


The correct way to resolve this problem is this:

When you save the image, use this instruction

Docker save --output=C:\YOUR_PATH\my_docker_image.tar e6f81ac424ae(image id)

And when you try to load this image, use this instruction:

Docker load --input C:\YOUR_PATH\my_docker_image.tar

After this you see your image with name <none> in Docker image, and to resolve this, use the command tag

Docker tag IMAGE_ID mydockerapplication