Home Explore Blog CI



docker

4th chunk of `content/guides/compose-bake/index.md`
b29511bca83540409b1a6eeed909bc1c8ddd849a206f5f7e0000000100000897
The Compose file currently defines the `dev` stage as the build target for the
`vote` service. That's appropriate for the image that you would run in local
development, because the `dev` stage includes additional development
dependencies and configurations. For the production image, however, you'll want
to target the `final` image instead.

To modify the target stage used by the `vote` service, add the following
configuration to the Bake file:

```hcl
target "vote" {
  target = "final"
}
```

This overrides the `target` property specified in the Compose file with a
different value when you run the build with Bake. The other build options in
the Compose file (tag, context) remain unmodified. You can verify by inspecting
the build configuration for the `vote` target with `docker buildx bake --print
vote`:

```json
{
  "group": {
    "default": {
      "targets": ["vote"]
    }
  },
  "target": {
    "vote": {
      "context": "vote",
      "dockerfile": "Dockerfile",
      "tags": ["username/vote"],
      "target": "final"
    }
  }
}
```

### Additional build features

Production-grade builds often have different characteristics from development
builds. Here are a few examples of things you might want to add for production
images.

Multi-platform
: For local development, you only need to build images for your local platform,
since those images are just going to run on your machine. But for images that
are pushed to a registry, it's often a good idea to build for multiple
platforms, arm64 and amd64 in particular.

Attestations
: [Attestations](/manuals/build/metadata/attestations/_index.md) are manifests
attached to the image that describe how the image was created and what
components it contains. Attaching attestations to your images helps ensure that
your images follow software supply chain best practices.

Annotations
: [Annotations](/manuals/build/metadata/annotations.md) provide descriptive
metadata for images. Use annotations to record arbitrary information and attach
it to your image, which helps consumers and tools understand the origin,
contents, and how to use the image.

> [!TIP]
> Why not just define these additional build options in the Compose file

Title: Overriding Target Stage and Additional Build Features
Summary
To modify the target stage used by the `vote` service, add a configuration to the Bake file. The `target` property specified in the Compose file is overridden with a different value when you run the build with Bake. Production-grade builds often have different characteristics from development builds. Examples of things you might want to add for production images include multi-platform support, attestations, and annotations.