COPY and ZIP files in Dockerfile 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?
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 &amp;&amp; tar xzf /tmp/file.gz &amp;&amp; rm /tmp/file.gz to only create a single layer without leaving the file behind.