Docker built-in way to download a file
The Old Way: Installing curl
FROM alpine:latest
WORKDIR /app
RUN apk add --no-cache curl
RUN curl -sS https://example.com/somefile.txt -o /app/somefile.txt
EXPOSE 8080
The Better Way: Using Docker’s ADD Instruction
FROM alpine:latest
WORKDIR /app
ADD https://example.com/anotherfile.json /app/anotherfile.json
EXPOSE 8080
- When to Use Each Approach 1
- Use
ADDwhen:- You’re downloading a single file from a URL
- The file doesn’t require authentication
- You want to keep your image minimal
- Stick with
curlorwgetwhen:- You need more control over the download (headers, authentication, retries)
- You’re fetching multiple files in a complex workflow
- You need to process or validate the downloaded content before using it
- Use