47

I'm installing sqlite on Alpine Linux. I download sqlite-autoconf-3130000.tar.gz but tar could not open it. I tried this answer but it's not working. tar gives this message:

tar: invalid magic
tar: short read

I wrote these commands.

wget https://www.sqlite.org/2015/sqlite-autoconf-3090100.tar.gz
tar -zxvf sqlite-autoconf-3090100.tar.gz
3
  • Could you please update your answer with the command (and its arguments) that you tried to run.
    – user14755
    Aug 9, 2016 at 6:56
  • 1
    Did the download complete successfully? If it did, ls -l sqlite-autoconf-3090100.tar.gz should tell you that the file is 2284128 bytes in size. Aug 9, 2016 at 7:50
  • Also, is it currently a gzip formatted file? Some browsers do on the fly decompression, meaning that it might still named sqlite-autoconf-3090100.tar.gz but that the contents might actually be sqlite-autoconf-3090100.tar. No idea if wget does equally smart things, but it is easily tested by leaving of the z flag from tar.
    – Hennes
    Jan 25, 2017 at 9:06

6 Answers 6

42

Try to install the tar package (apk add tar). Busybox tar (default) doesn't support all features.

1
  • 4
    I ran into the same issue when running a tar command in a Dockerfile and installing tar worked for me. It's kind of confusing because if you run the command in the shell in the container, it works. But not if it's a RUN command in the Dockerfile without having installed tar first. :| Oct 10, 2016 at 12:06
33

This doesn't necessarily mean the Alpine version of tar is incompatible, as Francesco pointed out you should really check your file checksums.

I ran into this while doing a curl https://github.com/someproject/releases/project-1.1.0.gz | tar -xvzf in my Dockerfile.

It turns out what I had forgotten was that curl will only follow redirects if you allow it with -L, and so it was never getting to the actual file, it was literally downloading the html telling it there was a redirect. Adding the -L allowed me to save the file without bloating my container with a new tar (beyond the "bloat" added by curl).

3
  • 5
    This is in fact the correct answer.
    – Steve Gore
    Feb 18, 2020 at 0:27
  • Not really, since it didn't work. We tried it with a -L and still gets the same error. May 10, 2022 at 20:02
  • In my case the URL had an environment variable that I forgot to set so instead of downloading a tar.gz I downloaded an HTML error page, which failed the tar extraction.
    – isapir
    Dec 27, 2022 at 20:08
1

if you use alpine in docker, please assert that you use COPY instead of ADD in your container file (Dockerfile) since ADD will decompress on building the layer

alpine default tar doesn't give you the hint

tar (child): sqlite-autoconf-3090100.tar.gz: Cannot read: Is a directory
tar (child): At beginning of tape, quitting now
tar (child): Error is not recoverable: exiting now
1

For me using the other compression format helped.

Compression format in some distros, has to be given explicitly for the tar utility. In the command, tar -zxvf instead of -z try using following formats.

-Z      (De)compress using compress
-z      (De)compress using gzip // this one we are already using in above case
-J      (De)compress using xz
-j      (De)compress using bzip2
-a      (De)compress using lzma

Hope it helps

0

tar:invalid magic means that the file is corrupted.

Please check the md5sum if matches...this is what i got:

 md5sum  sqlite-autoconf-3090100.tar.gz 
 74931054399a2d7acf35637efe8d6f45  sqlite-autoconf-3090100.tar.gz
0

I got the same issue and solved it, however I'm not sure you are facing the same issue.

Code that Caused error:

wget www.example.com/file.tar.gz
tar -zxvf file.tar.gz

Code that resolved it:

wget https://www.example.com/file.tar.gz
tar -zxvf file.tar.gz

Notice that I had forgoten the "https://" wherein the file did get downloaded but the tar gave me the same error. If the file is not found make sure you use

docker build --no-cache ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .