Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tar: Cannot read: Is a directory in docker

Tags:

docker

tar

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.

like image 225
white_gecko Avatar asked Jun 04 '14 22:06

white_gecko


3 Answers

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)

like image 91
white_gecko Avatar answered Nov 13 '22 10:11

white_gecko


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

like image 25
Kalle Avatar answered Nov 13 '22 12:11

Kalle


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.

like image 41
Joel Hoisko Avatar answered Nov 13 '22 11:11

Joel Hoisko