Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 586103a

Browse files
Merge component 'cli' from git@github.com:docker/cli 19.03
2 parents 97049ac + 9e55c7c commit 586103a

3 files changed

Lines changed: 150 additions & 4 deletions

File tree

components/cli/docs/reference/commandline/build.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Options:
4747
'host': use the Docker host network stack
4848
'<network-name>|<network-id>': connect to a user-defined network
4949
--no-cache Do not use cache when building the image
50+
-o, --output Output destination (format: type=local,dest=path)
5051
--pull Always attempt to pull a newer version of the image
5152
--progress Set type of progress output (only if BuildKit enabled) (auto, plain, tty).
5253
Use plain to show container output
@@ -323,7 +324,16 @@ Successfully built 99cc1ad10469
323324
This example shows the use of the `.dockerignore` file to exclude the `.git`
324325
directory from the context. Its effect can be seen in the changed size of the
325326
uploaded context. The builder reference contains detailed information on
326-
[creating a .dockerignore file](../builder.md#dockerignore-file)
327+
[creating a .dockerignore file](../builder.md#dockerignore-file).
328+
329+
When using the [BuildKit backend](../builder.md#buildkit), `docker build` searches
330+
for a `.dockerignore` file relative to the Dockerfile name. For example, running
331+
`docker build -f myapp.Dockerfile .` will first look for an ignore file named
332+
`myapp.Dockerfile.dockerignore`. If such a file is not found, the `.dockerignore`
333+
file is used if present. Using a Dockerfile based `.dockerignore` is useful if a
334+
project contains multiple Dockerfiles that expect to ignore different sets of
335+
files.
336+
327337

328338
### Tag an image (-t)
329339

@@ -489,6 +499,137 @@ FROM alpine AS production-env
489499
$ docker build -t mybuildimage --target build-env .
490500
```
491501

502+
### Custom build outputs
503+
504+
By default, a local container image is created from the build result. The
505+
`--output` (or `-o`) flag allows you to override this behavior, and a specify a
506+
custom exporter. For example, custom exporters allow you to export the build
507+
artifacts as files on the local filesystem instead of a Docker image, which can
508+
be useful for generating local binaries, code generation etc.
509+
510+
The value for `--output` is a CSV-formatted string defining the exporter type
511+
and options. Currently, `local` and `tar` exporters are supported. The `local`
512+
exporter writes the resulting build files to a directory on the client side. The
513+
`tar` exporter is similar but writes the files as a single tarball (`.tar`).
514+
515+
If no type is specified, the value defaults to the output directory of the local
516+
exporter. Use a hyphen (`-`) to write the output tarball to standard output
517+
(`STDOUT`).
518+
519+
The following example builds an image using the current directory (`.`) as build
520+
context, and exports the files to a directory named `out` in the current directory.
521+
If the directory does not exist, Docker creates the directory automatically:
522+
523+
```bash
524+
$ docker build -o out .
525+
```
526+
527+
The example above uses the short-hand syntax, omitting the `type` options, and
528+
thus uses the default (`local`) exporter. The example below shows the equivalent
529+
using the long-hand CSV syntax, specifying both `type` and `dest` (destination
530+
path):
531+
532+
```bash
533+
$ docker build --output type=local,dest=out .
534+
```
535+
536+
Use the `tar` type to export the files as a `.tar` archive:
537+
538+
```bash
539+
$ docker build --output type=tar,dest=out.tar .
540+
```
541+
542+
The example below shows the equivalent when using the short-hand syntax. In this
543+
case, `-` is specified as destination, which automatically selects the `tar` type,
544+
and writes the output tarball to standard output, which is then redirected to
545+
the `out.tar` file:
546+
547+
```bash
548+
docker build -o - . > out.tar
549+
```
550+
551+
The `--output` option exports all files from the target stage. A common pattern
552+
for exporting only specific files is to do multi-stage builds and to copy the
553+
desired files to a new scratch stage with [`COPY --from`](../builder.md#copy).
554+
555+
The example `Dockerfile` below uses a separate stage to collect the
556+
build-artifacts for exporting:
557+
558+
```Dockerfile
559+
FROM golang AS build-stage
560+
RUN go get -u github.com/LK4D4/vndr
561+
562+
FROM scratch AS export-stage
563+
COPY --from=build-stage /go/bin/vndr /
564+
```
565+
566+
When building the Dockerfile with the `-o` option, only the files from the final
567+
stage are exported to the `out` directory, in this case, the `vndr` binary:
568+
569+
```bash
570+
$ docker build -o out .
571+
572+
[+] Building 2.3s (7/7) FINISHED
573+
=> [internal] load build definition from Dockerfile 0.1s
574+
=> => transferring dockerfile: 176B 0.0s
575+
=> [internal] load .dockerignore 0.0s
576+
=> => transferring context: 2B 0.0s
577+
=> [internal] load metadata for docker.io/library/golang:latest 1.6s
578+
=> [build-stage 1/2] FROM docker.io/library/golang@sha256:2df96417dca0561bf1027742dcc5b446a18957cd28eba6aa79269f23f1846d3f 0.0s
579+
=> => resolve docker.io/library/golang@sha256:2df96417dca0561bf1027742dcc5b446a18957cd28eba6aa79269f23f1846d3f 0.0s
580+
=> CACHED [build-stage 2/2] RUN go get -u github.com/LK4D4/vndr 0.0s
581+
=> [export-stage 1/1] COPY --from=build-stage /go/bin/vndr / 0.2s
582+
=> exporting to client 0.4s
583+
=> => copying files 10.30MB 0.3s
584+
585+
$ ls ./out
586+
vndr
587+
```
588+
589+
> **Note**: This feature requires the BuildKit backend. You can either
590+
> [enable BuildKit](../builder.md#buildkit) or use the [buildx](https://github.com/docker/buildx)
591+
> plugin which provides more output type options.
592+
593+
### Specifying external cache sources
594+
595+
In addition to local build cache, the builder can reuse the cache generated from
596+
previous builds with the `--cache-from` flag pointing to an image in the registry.
597+
598+
To use an image as a cache source, cache metadata needs to be written into the
599+
image on creation. This can be done by setting `--build-arg BUILDKIT_INLINE_CACHE=1`
600+
when building the image. After that, the built image can be used as a cache source
601+
for subsequent builds.
602+
603+
Upon importing the cache, the builder will only pull the JSON metadata from the
604+
registry and determine possible cache hits based on that information. If there
605+
is a cache hit, the matched layers are pulled into the local environment.
606+
607+
In addition to images, the cache can also be pulled from special cache manifests
608+
generated by [`buildx`](https://github.com/docker/buildx) or the BuildKit CLI
609+
(`buildctl`). These manifests (when built with the `type=registry` and `mode=max`
610+
options) allow pulling layer data for intermediate stages in multi-stage builds.
611+
612+
The following example builds an image with inline-cache metadata and pushes it
613+
to a registry, then uses the image as a cache source on another machine:
614+
615+
```bash
616+
$ docker build -t myname/myapp --build-arg BUILDKIT_INLINE_CACHE=1 .
617+
$ docker push myname/myapp
618+
```
619+
620+
After pushing the image, the image is used as cache source on another machine.
621+
BuildKit automatically pulls the image from the registry if needed.
622+
623+
```bash
624+
# on another machine
625+
$ docker build --cache-from myname/myapp .
626+
```
627+
628+
> **Note**: This feature requires the BuildKit backend. You can either
629+
> [enable BuildKit](../builder.md#buildkit) or use the [buildx](https://github.com/docker/buildx)
630+
> plugin. The previous builder has limited support for reusing cache from
631+
> pre-pulled images.
632+
492633
### Squash an image's layers (--squash) (experimental)
493634

494635
#### Overview

components/cli/docs/reference/commandline/run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ machine. You can also specify `udp` and `sctp` ports.
352352
The [Docker User Guide](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/)
353353
explains in detail how to manipulate ports in Docker.
354354

355+
Note that ports which are not bound to the host (i.e., `-p 80:80` instead of
356+
`-p 127.0.0.1:80:80`) will be accessible from the outside. This also applies if
357+
you configured UFW to block this specific port, as Docker manages his
358+
own iptables rules. [Read more](https://docs.docker.com/network/iptables/)
359+
355360
```bash
356361
$ docker run --expose 80 ubuntu bash
357362
```

components/cli/docs/reference/commandline/search.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ be in the range between 1 and 100. The default value of `--limit` is 25.
9898
### Filtering
9999

100100
The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more
101-
than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`)
101+
than one filter, then pass multiple flags (e.g. `--filter is-automated=true --filter stars=3`)
102102

103103
The currently supported filters are:
104104

@@ -126,7 +126,7 @@ This example displays images with a name containing 'busybox'
126126
and are automated builds:
127127

128128
```bash
129-
$ docker search --filter is-automated busybox
129+
$ docker search --filter is-automated=true busybox
130130

131131
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
132132
progrium/busybox 50 [OK]
@@ -139,7 +139,7 @@ This example displays images with a name containing 'busybox', at least
139139
3 stars and are official builds:
140140

141141
```bash
142-
$ docker search --filter "is-official=true" --filter "stars=3" busybox
142+
$ docker search --filter is-official=true --filter stars=3 busybox
143143

144144
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
145145
progrium/busybox 50 [OK]

0 commit comments

Comments
 (0)