ADD --unpack for downloading and extracting remote archives.
| Property | Value |
|---|---|
| Severity | Info |
| Category | Performance |
| Default | Enabled |
| Auto-fix | Yes (--fix --fix-unsafe) |
Description
FlagsRUN instructions that download a remote tar archive with curl / wget, Windows curl.exe / wget.exe, or PowerShell
Invoke-WebRequest / iwr, and extract it with tar, suggesting
ADD --unpack <url> <dest> instead.
ADD --unpack is a BuildKit feature that downloads and extracts a remote tar archive in a single layer,
reducing image size and build complexity. It is implemented directly in BuildKit’s Go codepath, so it works on Windows containers too and avoids
spawning download and extraction processes inside the build container.
Detected Patterns
- Pipe pattern:
curl -fsSL <url> | tar -xz -C /dest - Download-then-extract:
curl -o /tmp/app.tar.gz <url> && tar -xf /tmp/app.tar.gz -C /dest - wget variants: Same patterns with
wgetinstead ofcurl - Windows cmd variants:
curl.exe ... -o C:\tmp\app.tar.gz && tar.exe -xf C:\tmp\app.tar.gz -C C:\tools - PowerShell variants:
Invoke-WebRequest ... -OutFile C:\tmp\app.tar.gz; tar.exe -xf C:\tmp\app.tar.gz -C C:\tools
tar extraction command is present in the same RUN instruction.
Examples
Before (violation)
After (fixed with —fix —fix-unsafe)
Auto-fix Conditions
The auto-fix is only emitted when:- The
RUNinstruction contains only download and extraction commands (curl/wget/curl.exe/wget.exe/Invoke-WebRequest/iwr+tar) - A
tarextraction command is present (ADD --unpackonly handles tar archives)
chmod, rm, mv), the violation is still reported but no fix is suggested, since those commands would be
lost.
The tar destination is extracted from -C, --directory=, or --directory flags. If no destination is specified, the effective WORKDIR is used.
Limitations
- PowerShell and Windows support is limited to download-then-extract patterns; POSIX-style pipe detection remains POSIX-shell-only
- Only detects
tarextraction (ADD --unpackdoes not handle single-file decompressors) - Does not match ZIP-oriented flows such as
Expand-Archive - URL must have a recognized archive file extension
Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable the rule |