For most production use cases, it is best to use a single RUN instruction that downloads, unzips, and then immediately deletes the original archive. This prevents the large compressed file from being saved as a permanent layer in your final image. dockerfile
The ADD instruction can fetch a file from a URL directly. However, it is important to note that ; it only auto-extracts local .tar archives. If you use ADD for a remote .zip , you will still need a subsequent RUN unzip command. Example using ADD : dockerfile dockerfile download file from url and unzip
FROM alpine:latest # Install unzip since it is not always included in base images RUN apk add --no-cache curl unzip # Download, unzip, and cleanup in one step to keep the image small RUN curl -L https://example.com -o /tmp/archive.zip && \ unzip /tmp/archive.zip -d /app/data && \ rm /tmp/archive.zip Use code with caution. The Quick Method: ADD Instruction For most production use cases, it is best
Downloading and unzipping files within a Dockerfile is a common task, but doing it efficiently is crucial for keeping your image sizes small and your builds fast. The Recommended Method: RUN with curl or wget However, it is important to note that ;
Note: Using this method leaves the .zip file in the previous layer's cache, which increases the total image size. Best Practices for Downloading and Unzipping