I get this error tar: Archive is compressed. Use -z option when trying to build my docker image:

RUN wget https://github.com/wal-g/wal-g/releases/download/v2.0.1/wal-g-pg-ubuntu-20.04-amd64.tar.gz -O - | \
  tar -xvf - -O > "${APP}/bin/wal-g"

But why this error happen when -z option is ignored in extract mode?

-z, --gunzip, --gzip
(c mode only) Compress the resulting archive with gzip(1). In extract or list modes, this
option is ignored. Note that this tar implementation recognizes gzip compression automatically when reading archives.

When I add -z option, I get another error:

Cannot write to ‘-’ (Success).

1 Answer 1


The command should be:

wget https://github.com/wal-g/wal-g/releases/download/v2.0.1/wal-g-pg-ubuntu-20.04-amd64.tar.gz -O - |   tar zxvf - -O > "${APP}/bin/wal-g"

The z needs to be added somewhere not between -f and -. The option -f requires an argument, which in this case is -.

Here is how -f aka --file option is defined in the tar source code:

  {"file", 'f', N_("ARCHIVE"), 0,
   N_("use archive file or device ARCHIVE"), GRID_DEVICE },

You can see from the code that -f needs to be followed by a file name, in this case the special name - which means stdout(3).

It seems that tar is using GNU argp for parsing the CLI arguments instead of getopt(3).

  • Ok. But question was: why I need -z if it is ignored in extract mode? Oct 3 at 17:39
  • Where did you put the -z ? From my understanding, I suspect that you appended z at the end of the options, like -xvfz - which is incorrect, as -f needs an argument, in your case, the argument is -. You can use -xvf - -z or -xvzf - or -zxvf - Oct 3 at 17:53
  • 1
    I think you are reading the wrong manual page. Are you using GNU tar? Oct 3 at 18:10
  • 5
    @EugenKonkov The tar in the container is likely not the same implementation as your host OS. It will depend on the image, but if its one that uses busybox, it does not have that auto-detection and will need the -z option Oct 4 at 0:51
  • 1
    Nit: -f - means stdout when writing an archive but stdin when extracting or listing. @ColonelThirtyTwo+ GNU tar autodetection fails (and gives the error message in the Q, which busybox does not) when the input is unseekable which is the case in this Q; bsdtar works in this case (at least in my systems) Oct 4 at 9:04

You must log in to answer this question.

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