6

Using a COPY statement creates a new image layer, right?

COPY files/foo.zip /tmp/

Now, to save space I could take the ADD statement... for a GZ arhive. But ADD does not support automatic extraction of ZIP files.

So the foo.zip will be dangling around somewhere in a below layer. Just a RUN rm statement does not help.

How do you solve this?

Ta Mu
  • 6,772
  • 5
  • 39
  • 82

1 Answers1

7

Convert the zip file into a gz file before running docker build, possibly in a wrapper script.

Or even go one step further, and extract the archive first, then use COPY to copy the resulting folder contents.

When you are using archives from the internet on the other hand, ADD http://somewhere/file.gz /data will extract the downloaded file directly into that folder. If you have a problem with zip/gz format there, then use RUN curl -o somewhere/file.gz /tmp/file.gz && tar xzf /tmp/file.gz && rm /tmp/file.gz to only create a single layer without leaving the file behind.

Evgeny Zislis
  • 8,963
  • 5
  • 38
  • 72
  • 2
    If you go this way, just pipe curl output to tar and avoid using a tempfile should improve the time spent. – Tensibai Jan 24 '18 at 13:16