Answers: <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>
  
Answers: CC BY-SA 3.0
Answers: 2018-01-24T13:16:42.413Z
Answers: If you go this way, just pipe curl output to tar and avoid using a tempfile should improve the time spent.
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-01-24T13:05:04.503Z
Answers: 2018-01-24T13:05:04.503Z
Answers: Evgeny Zislis
Body: <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>
  
Comments: CC BY-SA 3.0
Comments: 2018-01-24T08:46:16.637Z
Comments: 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 ...
Comments: Tensibai
Tags: <dockerfile>
Title: COPY and ZIP files in Dockerfile
UserDisplayName: Ta Mu
ThreadText: # 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](https://github.com/moby/moby/issues/32745) 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.  
  
  ---
  
  