Skip to content

Commit

Permalink
Docs: build-contexts and bake options
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Baibaratsky <andrei@baibaratsky.com>
  • Loading branch information
baibaratsky committed Aug 13, 2022
1 parent e8f37dc commit ced7fb7
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions docs/advanced/export-docker.md
Expand Up @@ -38,8 +38,8 @@ jobs:
## Usage of the built image in other build steps

[By default](https://github.com/docker/setup-buildx-action#customizing), `docker/setup-buildx-action@v2`
uses `docker-container` as a build driver, so the docker images are not available in the container.
To use them, you may change the build driver to `docker`:
uses `docker-container` as a build driver, so the docker images are not available in the builder container.
To use them, you may use [build contexts](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-additional-build-contexts---build-context):

```yaml
name: ci
Expand All @@ -59,8 +59,6 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver: docker # for images in Docker to be available in build steps
-
name: Build base image
uses: docker/build-push-action@v3
Expand All @@ -73,5 +71,37 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
build-contexts: |
base-image=docker-image://my-base-image:latest
tags: myimage:latest
```

Where `base-image`is the name of the base image (or stage name if specified) in your Dockerfile:
```Dockerfile
FROM base-image
```

### Bake alternative

You may also want to use [bake](https://docs.docker.com/build/bake/build-contexts/#using-a-result-of-one-target-as-a-base-image-in-another-target)
and build the base image and the target image in one build step:
```terraform
# docker-bake.hcl
target "base" {
dockerfile = "baseapp.Dockerfile"
}
target "app" {
contexts = {
baseapp = "target:base"
}
}
```

```yaml
-
name: Build
uses: docker/bake-action@v2
with:
target: app
```

0 comments on commit ced7fb7

Please sign in to comment.