Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ fetch-remote:
- "!docs/README.md" # readme to make things nice in the compose-cli repo, but meaningless here
- "!docs/architecture.md" # Compose-CLI architecture, unrelated to cloud integration

- repo: "https://github.com/docker/buildx"
ref: "master"
paths:
- dest: "build/guides"
src:
- "docs/guides/*.md"
- "!docs/guides/cicd.md" # CI/CD documentation is already handled in ci-cd/github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what we're doing here, is this about removing something from the docs that is some repo? If so, I'm not sure that is the right way forward.

Copy link
Member Author

@crazy-max crazy-max Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are fetching markdown files from buildx repo in https://github.com/docker/buildx/tree/master/docs/guides (except ci-cd) and add them to build/guides folder here.
Will be available in Manuals > Docker Build > Guides. See https://deploy-preview-14905--docsdocker.netlify.app/build/guides/cni-networking/

- dest: "build/bake"
src:
- "docs/guides/bake/**"

- repo: "https://github.com/distribution/distribution"
default_branch: "main"
ref: "release/2.7"
Expand Down
36 changes: 34 additions & 2 deletions _data/toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ guides:
title: Dockerfile best practices
- path: /develop/develop-images/build_enhancements/
title: Build images with BuildKit
- path: /develop/develop-images/multistage-build/
title: Use multi-stage builds
- path: /develop/develop-images/image_management/
title: Manage images
- path: /develop/develop-images/baseimages/
Expand Down Expand Up @@ -1396,6 +1394,40 @@ manuals:
title: Working with Buildx
- path: /build/buildx/install/
title: Install Buildx
- sectiontitle: Bake
section:
- path: /build/bake/
title: Overview
- path: /build/bake/file-definition/
title: File definition
- path: /build/bake/configuring-build/
title: Configuring builds
- path: /build/bake/hcl-funcs/
title: User defined HCL functions
- path: /build/bake/build-contexts/
title: Build contexts and linking targets
- path: /build/bake/compose-file/
title: Building from Compose file
- sectiontitle: Guides
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh this seems strange to me, but not sure whether there's a better alternative.

Having a section in Manuals called Guides, when we have a Guides category 🤔 I feel like it's better to maybe be consistent with the rest of our docs for now, and put it into Guides?

Other options:

  • Don't call them "Guides" but something like "Advanced usage"? But then of course, what happens if we add more entry-level guides/tutorials, do those go into the guides section (splitting them up), or do we keep them together, which seems inconsistent with the rest of the docs.
  • Rework the buildkit guides to be more like the guides in the rest of the docs, by making them more tutorial like, etc - maybe the remote builder guide is already like this in style?

section:
- path: /build/guides/cni-networking/
title: CNI networking
- path: /build/guides/custom-network/
title: Using a custom network
- path: /build/guides/custom-registry-config/
title: Using a custom registry config
- path: /build/guides/kubernetes-builder/
title: Kubernetes builder
- path: /build/guides/multi-stage-build/
title: Multi-stage builds
- path: /build/guides/opentelemetry/
title: OpenTelemetry support
- path: /build/guides/registry-mirror/
title: Define a registry mirror
- path: /build/guides/remote-builder/
title: Remote builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should group this near the kubernetes builder. Maybe we also want to call it <x>-driver instead of <x>-builder - really not sure on that though.

- path: /build/guides/resource-limiting/
title: Resource limiting

- sectiontitle: Docker Compose
section:
Expand Down
2 changes: 1 addition & 1 deletion _layouts/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5 class="title">How do I?</h5>
<div class="col-xs-12 col-md-6"><a href="/config/daemon/">Configure the Docker daemon</a></div>
<div class="col-xs-12 col-md-6"><a href="/get-started/02_our_app/">Build and run an image</a></div>
<div class="col-xs-12 col-md-6"><a href="/config/labels-custom-metadata/">Manage Docker objects</a></div>
<div class="col-xs-12 col-md-6"><a href="/develop/develop-images/multistage-build/">Use multi-stage builds</a></div>
<div class="col-xs-12 col-md-6"><a href="/build/guides/multi-stage-build/">Multi-stage builds</a></div>
<div class="col-xs-12 col-md-6"><a href="/get-started/swarm-deploy/">Scale apps using Swarm</a></div>
</div>
</div>
Expand Down
26 changes: 4 additions & 22 deletions build/buildx/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,7 @@ FROM alpine
COPY --from=build /log /log
```

## High-level build options

Buildx also aims to provide support for high-level build concepts that go beyond
invoking a single build command.

BuildKit efficiently handles multiple concurrent build requests and de-duplicating
work. The build commands can be combined with general-purpose command runners
(for example, `make`). However, these tools generally invoke builds in sequence
and therefore cannot leverage the full potential of BuildKit parallelization,
or combine BuildKit’s output for the user. For this use case, we have added a
command called [`docker buildx bake`](../../engine/reference/commandline/buildx_bake.md).

The `bake` command supports building images from compose files, similar to
[`docker-compose build`](../../engine/reference/commandline/compose_build.md),
but allowing all the services to be built concurrently as part of a single
request.

There is also support for custom build rules from HCL/JSON files allowing
better code reuse and different target groups. The design of bake is in very
early stages, and we are looking for feedback from users. Let us know your
feedback by creating an issue in the [Docker Buildx](https://github.com/docker/buildx/issues){:target="_blank" rel="noopener" class="_"}
GitHub repository.
## High-level build options with Bake

Check out our guide about [Bake](../bake/index.md) to get started with the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to call out that bake is still experimental here as well?

[`docker buildx bake` command](../../engine/reference/commandline/buildx_bake.md).
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
description: Keeping your images small with multi-stage images
keywords: images, containers, best practices, multi-stage, multistage
title: Use multi-stage builds
title: Multi-stage builds
description: Keeping your images small with multi-stage builds
keywords: build, best practices
redirect_from:
- /engine/userguide/eng-image/multistage-build/
- /develop/develop-images/multistage-build/
---

Multistage builds are useful to anyone who has struggled to optimize Dockerfiles
while keeping them easy to read and maintain.
Multi-stage builds are useful to anyone who has struggled to optimize
Dockerfiles while keeping them easy to read and maintain.

> **Acknowledgment**:
> **Acknowledgment**
>
> Special thanks to [Alex Ellis](https://twitter.com/alexellisuk) for granting
> permission to use his blog post
> [Builder pattern vs. Multi-stage builds in Docker](https://blog.alexellis.io/mutli-stage-docker-builds/)
> permission to use his blog post [Builder pattern vs. Multi-stage builds in Docker](https://blog.alexellis.io/mutli-stage-docker-builds/)
> as the basis of the examples below.

## Before multi-stage builds
Expand All @@ -31,10 +32,10 @@ to use for production, which only contained your application and exactly what
was needed to run it. This has been referred to as the "builder
pattern". Maintaining two Dockerfiles is not ideal.

Here's an example of a `Dockerfile.build` and `Dockerfile` which adhere to the
Here's an example of a `build.Dockerfile` and `Dockerfile` which adhere to the
builder pattern above:

**`Dockerfile.build`**:
**`build.Dockerfile`**:

```dockerfile
# syntax=docker/dockerfile:1
Expand Down Expand Up @@ -66,16 +67,13 @@ CMD ["./app"]
```bash
#!/bin/sh
echo Building alexellis2/href-counter:build

docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \
-t alexellis2/href-counter:build . -f Dockerfile.build
docker build -t alexellis2/href-counter:build . -f build.Dockerfile

docker container create --name extract alexellis2/href-counter:build
docker container cp extract:/go/src/github.com/alexellis/href-counter/app ./app
docker container rm -f extract

echo Building alexellis2/href-counter:latest

docker build --no-cache -t alexellis2/href-counter:latest .
rm ./app
```
Expand Down Expand Up @@ -143,7 +141,7 @@ Dockerfile are re-ordered later, the `COPY` doesn't break.
FROM golang:1.16 AS builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go ./
COPY app.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest
Expand Down Expand Up @@ -186,7 +184,8 @@ COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf

## Use a previous stage as a new stage

You can pick up where a previous stage left off by referring to it when using the `FROM` directive. For example:
You can pick up where a previous stage left off by referring to it when using
the `FROM` directive. For example:

```dockerfile
# syntax=docker/dockerfile:1
Expand All @@ -204,4 +203,4 @@ RUN g++ -o /binary source.cpp

## Version compatibility

Multistage build syntax was introduced in Docker Engine 17.05.
Multi-stage build syntax was introduced in Docker Engine 17.05.
2 changes: 1 addition & 1 deletion compose/compose-file/compose-file-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ build:
> Added in [version 2.3](compose-versioning.md#version-23) file format

Build the specified stage as defined inside the `Dockerfile`. See the
[multi-stage build docs](../../develop/develop-images/multistage-build.md) for
[multi-stage build docs](../../build/guides/multi-stage-build.md) for
details.

```yaml
Expand Down
2 changes: 1 addition & 1 deletion compose/compose-file/compose-file-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ build:
> Added in [version 3.4](compose-versioning.md#version-34) file format

Build the specified stage as defined inside the `Dockerfile`. See the
[multi-stage build docs](../../develop/develop-images/multistage-build.md) for
[multi-stage build docs](../../build/guides/multi-stage-build.md) for
details.

```yaml
Expand Down
2 changes: 1 addition & 1 deletion develop/dev-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ keep image size small:
starting with a generic `ubuntu` image and installing `openjdk` as part of the
Dockerfile.

- [Use multistage builds](develop-images/multistage-build.md). For
- [Use multistage builds](../build/guides/multi-stage-build.md). For
instance, you can use the `maven` image to build your Java application, then
reset to the `tomcat` image and copy the Java artifacts into the correct
location to deploy your app, all in the same Dockerfile. This means that your
Expand Down
14 changes: 7 additions & 7 deletions develop/develop-images/dockerfile_best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ similar to `.gitignore` files. For information on creating one, see the

### Use multi-stage builds

[Multi-stage builds](multistage-build.md) allow you to drastically reduce the
size of your final image, without struggling to reduce the number of intermediate
layers and files.
[Multi-stage builds](../../build/guides/multi-stage-build.md) allow you to
drastically reduce the size of your final image, without struggling to reduce
the number of intermediate layers and files.

Because an image is built during the final stage of the build process, you can
minimize image layers by [leveraging build cache](#leverage-build-cache).
Expand Down Expand Up @@ -334,10 +334,10 @@ were added to reduce this limitation:
- Only the instructions `RUN`, `COPY`, `ADD` create layers. Other instructions
create temporary intermediate images, and do not increase the size of the build.

- Where possible, use [multi-stage builds](multistage-build.md), and only copy
the artifacts you need into the final image. This allows you to include tools
and debug information in your intermediate build stages without increasing the
size of the final image.
- Where possible, use [multi-stage builds](../../build/guides/multi-stage-build.md),
and only copy the artifacts you need into the final image. This allows you to
include tools and debug information in your intermediate build stages without
increasing the size of the final image.

### Sort multi-line arguments

Expand Down
2 changes: 1 addition & 1 deletion develop/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ these resources to understand some of the most common patterns for getting the
most benefits from Docker.

- Learn how to [build an image](../engine/reference/builder/){: target="_blank" rel="noopener" class="_"} using a Dockerfile
- Use [multi-stage builds](develop-images/multistage-build.md){: target="_blank" rel="noopener" class="_"} to keep your images lean
- Use [multi-stage builds](../build/guides/multi-stage-build.md){: target="_blank" rel="noopener" class="_"} to keep your images lean
- Manage application data using [volumes](../storage/volumes.md) and [bind mounts](../storage/bind-mounts.md){: target="_blank" rel="noopener" class="_"}
- [Scale your app with Kubernetes](../get-started/kube-deploy.md){: target="_blank" rel="noopener" class="_"}
- [Scale your app as a Swarm service](../get-started/swarm-deploy.md){: target="_blank" rel="noopener" class="_"}
Expand Down
2 changes: 1 addition & 1 deletion develop/scan-images/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ You can use multiple `FROM` statements in your Dockerfile, and you can use a dif

This method of creating a tiny image does not only significantly reduce complexity, but also the change of implementing vulnerable artifacts in your image. Therefore, instead of images that are built on images, that again are built on other images, multi-stage builds allow you to 'cherry pick' your artifacts without inheriting the vulnerabilities from the base images on which they rely on.

For detailed information on how to configure multi-stage builds, see [multi-stage builds](../develop-images/multistage-build.md).
For detailed information on how to configure multi-stage builds, see [multi-stage builds](../../build/guides/multi-stage-build.md).

### Rebuild images

Expand Down
2 changes: 1 addition & 1 deletion language/golang/build-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ that we have used to deploy our Go application is very barebones and is meant
for lean deployments of static binaries.

For more information on multi-stage builds, please feel free to check out
[other parts](../../develop/develop-images/multistage-build.md) of the Docker
[other parts](../../build/guides/multi-stage-build.md) of the Docker
documentation. This is, however, not essential for our progress here, so we'll
leave it at that.

Expand Down
2 changes: 1 addition & 1 deletion storage/storagedriver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ _adding_, and _removing_ files will result in a new layer. In the example above,
the `$HOME/.cache` directory is removed, but will still be available in the
previous layer and add up to the image's total size. Refer to the
[Best practices for writing Dockerfiles](../../develop/develop-images/dockerfile_best-practices.md)
and [use multi-stage builds](../../develop/develop-images/multistage-build.md)
and [use multi-stage builds](../../build/guides/multi-stage-build.md)
sections to learn how to optimize your Dockerfiles for efficient images.

The layers are stacked on top of each other. When you create a new container,
Expand Down