<p>Convert the <code>zip</code> file into a <code>gz</code> file before running <code>docker build</code>, possibly in a wrapper script.</p>

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

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

CC BY-SA 3.0
2018-01-24T13:16:42.413Z
If you go this way, just pipe curl output to tar and avoid using a tempfile should improve the time spent.
Tensibai
CC BY-SA 3.0
2018-01-24T13:05:04.503Z
2018-01-24T13:05:04.503Z
Evgeny Zislis
<p>Using a <code>COPY</code> statement creates a new image layer, right?</p>

<pre><code>COPY files/foo.zip /tmp/
</code></pre>

<p>Now, to save space I could take the <code>ADD</code> statement... for a GZ arhive. But <code>ADD</code> <a href="https://github.com/moby/moby/issues/32745" rel="noreferrer">does not support</a> automatic extraction of ZIP files.</p>

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

<p>How do you solve this?</p>

CC BY-SA 3.0
2018-01-24T08:46:16.637Z
What does not answer your question in [How to create the smallest working docker image every time?](https://devops.stackexchange.com/q/413/13) ? This sounds like a duplicate ...
Tensibai
<dockerfile>
COPY and ZIP files in Dockerfile
Ta Mu
# COPY and ZIP files in Dockerfile

(Asked by: username_0 on 2018-01-24)

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?

**Tags:** dockerfile

> **Comments:**
> **username_1**: What does not answer your question in [How to create the smallest working docker image every time?](https://devops.stackexchange.com/q/413/13) ? This sounds like a duplicate ...  

---

## 1 answers

### Answer by username_2 on 2018-01-24. Score: 7 | Accepted answer

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.

> **Comments:**
> **username_1**: If you go this way, just pipe curl output to tar and avoid using a tempfile should improve the time spent.  

---

