Docker Community Forums

Share and learn in the Docker community.

Docker not extracting .tar.xz archives

Hello, this is my first post on this forum, so be gentle :wink:

Into the Docker file I’ve put

ADD archive.tar.xz /opt/app

but after the docker image is built, /opt/app isn’t a directory containing the files, but it’s a xz compressed file.

/opt/app: XZ compressed data

I have tested it with tar.gz, but it’d be much better if I was able to use the tar.xz, as the image is about 350MB in size(tar.gz's image is about 500MB).

If there’s another way to achieve the same by manually extracting, I’d love to hear about it!

Thanks!
MGlolenstine

EDIT
I’ve read about the ADD command on https://docs.docker.com/engine/reference/builder/#add and I understand

If <src> is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources from remote URLs are not decompressed. When a directory is copied or unpacked, it has the same behavior as tar -x , the result is the union of:
-1. Whatever existed at the destination path and
-2. The contents of the source tree, with conflicts resolved in favor of “2.” on a file-by-file basis.

like it should be working for the tar.xz.

EDIT #2
The file I’m trying to extract is indeed the tar.xz archive, not only by the extension, but by the magic bytes as well.

archive.tar.xz: XZ compressed data

EDIT #3
I changed the compression rate of the tar.gz archive to -9, so the crisis averted for now, but I’d still love to know if this is a bug or if I’m doing something wrong.