white_gecko
white_gecko

Reputation: 5086

tar: Cannot read: Is a directory in docker

I want to add an archive (.tar.gz) and unpack it during image creation using a Dockerfile.

ADD archive.tar.gz /archive.tar.gz
RUN tar xzf archive.tar.gz

When I want to unpack the archive, I get following message:

tar: /archive.tar.gz: Cannot read: Is a directory
tar: At beginning of tape, quitting now
tar: Error is not recoverable: exiting now

which doesn't make any sense to me, since the file archive.tar.gz is not a directory.

Upvotes: 25

Views: 21745

Answers (3)

Joel Hoisko
Joel Hoisko

Reputation: 92

For others who have run into this problem more recently when referencing remote urls with their ADD commands, this is a problem with Docker 17.06.0-ce (2017-06-28).

From Dockers release notes:

Note: Docker 17.06.0 has an issue in the image builder causing a change in the behavior of the ADD instruction of Dockerfile when referencing a remote .tar.gz file. The issue will be fixed in Docker 17.06.1.

Upvotes: 1

white_gecko
white_gecko

Reputation: 5086

After running an intermediate commit of the docker image I could see, that /archive.tar.gz indeed is a directory. This means that docker automatically extracts archives when adding them during image creation.

Now I could also find this documented in docker documentation.

(edit: files, e.g. .sql.gz, are not decompressed on adding)

Upvotes: 32

Kalle
Kalle

Reputation: 13346

If you want the archive to remain as is use COPY, not ADD.

Upvotes: 4

Related Questions