Skip to content

Commit 192bdc3

Browse files
authored
Merge pull request #6305 from dvdksn/add-unpack-docs
docs: explain ADD --unpack flag
2 parents 60e51d4 + 0492d14 commit 192bdc3

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

frontend/dockerfile/docs/reference.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,8 @@ ADD arr[[]0].txt /dest/
14341434

14351435
When using a local tar archive as the source for `ADD`, and the archive is in a
14361436
recognized compression format (`gzip`, `bzip2` or `xz`, or uncompressed), the
1437-
archive is decompressed and extracted into the specified destination. Only
1438-
local tar archives are extracted. If the tar archive is a remote URL, the
1439-
archive is not extracted, but downloaded and placed at the destination.
1437+
archive is decompressed and extracted into the specified destination. Local tar
1438+
archives are extracted by default, see the [`ADD --unpack` flag].
14401439

14411440
When a directory is extracted, it has the same behavior as `tar -x`.
14421441
The result is the union of:
@@ -1461,6 +1460,9 @@ file. However, like any other file processed during an `ADD`, `mtime` isn't
14611460
included in the determination of whether or not the file has changed and the
14621461
cache should be updated.
14631462

1463+
If remote file is a tar archive, the archive is not extracted by default. To
1464+
download and extract the archive, use the [`ADD --unpack` flag].
1465+
14641466
If the destination ends with a trailing slash, then the filename is inferred
14651467
from the URL path. For example, `ADD http://example.com/foobar /` would create
14661468
the file `/foobar`. The URL must have a nontrivial path so that an appropriate
@@ -1595,6 +1597,26 @@ See [`COPY --link`](#copy---link).
15951597

15961598
See [`COPY --exclude`](#copy---exclude).
15971599

1600+
### ADD --unpack
1601+
1602+
```dockerfile
1603+
ADD [--unpack=<bool>] <src> ... <dir>
1604+
```
1605+
1606+
The `--unpack` flag controls whether or not to automatically unpack tar
1607+
archives (including compressed formats like `gzip` or `bzip2`) when adding them
1608+
to the image. Local tar archives are unpacked by default, whereas remote tar
1609+
archives (where `src` is a URL) are downloaded without unpacking.
1610+
1611+
```dockerfile
1612+
# syntax=docker/dockerfile:1
1613+
FROM alpine
1614+
# Download and unpack archive.tar.gz into /download:
1615+
ADD --unpack=true https://example.com/archive.tar.gz /download
1616+
# Add local tar without unpacking:
1617+
ADD --unpack=false my-archive.tar.gz .
1618+
```
1619+
15981620
## COPY
15991621

16001622
COPY has two forms.

0 commit comments

Comments
 (0)