HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

COPY and ZIP files in Dockerfile

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
zipdockerfilefilesandcopy

Problem

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?

Solution

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.

Context

StackExchange DevOps Q#3172, answer score: 7

Revisions (0)

No revisions yet.