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

27,812

Solution 1

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).

Solution 2

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.

Solution 3

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

Solution 4

The problem was in FTPing the TAR file to my AWS instance - the FTP client was defaulting to ASCII mode instead of binary. Once I set it to binary I had no problems importing the archive.

Share:
27,812
bicster
Author by

bicster

Updated on May 02, 2020

Comments

  • bicster
    bicster about 4 years

    I'm trying to import a Docker image into Docker on AWS Red Hat Linux (3.10.0-514.el7.x86_64) and am having problems with the error;

    Error processing tar file(exit status 1): archive/tar: invalid tar header
    

    This same image works fine on my local machine, and in Boot2Docker on Windows also. It's quite large (2.5 GB), but I've verified the checksum on the Red Hat Linux instance, and it's the same as from the source.

    What could be wrong, or how I can resolve it?

  • Peter Mortensen
    Peter Mortensen over 5 years
    Can't you use an HTTP transfer instead of FTP?
  • Chris Barlow
    Chris Barlow over 5 years
    I've been trying to figure out why my image ballooned in size by 2x all day -- this was it. You're the best and everybody loves you.
  • Shadi
    Shadi over 2 years
    Exactly, using CMD instead of PowerShell while placing -o for save and -i for load worked for me :) Thanks!
  • P. Sithole
    P. Sithole about 2 years
    docker load --input C:\YOUR_PATH\my_docker_image.tar worked wonders for me