bicster
bicster

Reputation: 820

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

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?

Upvotes: 55

Views: 72132

Answers (5)

suhas yadav
suhas yadav

Reputation: 1

Use podman push instead of skopeo.

Ex:

skopeo -skopeo:xxxxxxxxxxxxxxxx.tgz

podman - podman:xxxxxxxxxxxxxxx.tgz

Upvotes: 0

GiskardReventlov
GiskardReventlov

Reputation: 333

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.

Upvotes: 33

bicster
bicster

Reputation: 820

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.

Upvotes: 1

daniele3004
daniele3004

Reputation: 13950

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

Upvotes: 4

Ostecke
Ostecke

Reputation: 1759

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

Upvotes: 107

Related Questions