3

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?

3

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.