Home Explore Blog CI



docker

content/manuals/build/bake/introduction.md
0399c0cc8a0d54b1928ae66c424fcfa2289501deee6c21070000000300000be0
---
title: Introduction to Bake
linkTitle: Introduction
weight: 10
description: Get started with using Bake to build your project
keywords: bake, quickstart, build, project, introduction, getting started
---

Bake is an abstraction for the `docker build` command that lets you more easily
manage your build configuration (CLI flags, environment variables, etc.) in a
consistent way for everyone on your team.

Bake is a command built into the Buildx CLI, so as long as you have Buildx
installed, you also have access to bake, via the `docker buildx bake` command.

## Building a project with Bake

Here's a simple example of a `docker build` command:

```console
$ docker build -f Dockerfile -t myapp:latest .
```

This command builds the Dockerfile in the current directory and tags the
resulting image as `myapp:latest`.

To express the same build configuration using Bake:

```hcl {title=docker-bake.hcl}
target "myapp" {
  context = "."
  dockerfile = "Dockerfile"
  tags = ["myapp:latest"]
}
```

Bake provides a structured way to manage your build configuration, and it saves
you from having to remember all the CLI flags for `docker build` every time.
With this file, building the image is as simple as running:

```console
$ docker buildx bake myapp
```

For simple builds, the difference between `docker build` and `docker buildx
bake` is minimal. However, as your build configuration grows more complex, Bake
provides a more structured way to manage that complexity, that would be
difficult to manage with CLI flags for the `docker build`. It also provides a
way to share build configurations across your team, so that everyone is
building images in a consistent way, with the same configuration.

## The Bake file format

You can write Bake files in HCL, YAML (Docker Compose files), or JSON. In
general, HCL is the most expressive and flexible format, which is why you'll
see it used in most of the examples in this documentation, and in projects that
use Bake.

The properties that can be set for a target closely resemble the CLI flags for
`docker build`. For instance, consider the following `docker build` command:

```console
$ docker build \
  -f Dockerfile \
  -t myapp:latest \
  --build-arg foo=bar \
  --no-cache \
  --platform linux/amd64,linux/arm64 \
  .
```

The Bake equivalent would be:

```hcl {title=docker-bake.hcl}
target "myapp" {
  context = "."
  dockerfile = "Dockerfile"
  tags = ["myapp:latest"]
  args = {
    foo = "bar"
  }
  no-cache = true
  platforms = ["linux/amd64", "linux/arm64"]
}
```

> [!TIP]
>
> Want a better editing experience for Bake files in VS Code?
> Check out the [Docker VS Code Extension (Beta)](https://marketplace.visualstudio.com/items?itemName=docker.docker) for linting, code navigation, and vulnerability scanning.

## Next steps

To learn more about using Bake, see the following topics:

- Learn how to define and use [targets](./targets.md) in Bake
- To see all the properties that can be set for a target, refer to the
  [Bake file reference](/build/bake/reference/).

Chunks
e9db26c1 (1st chunk of `content/manuals/build/bake/introduction.md`)
Title: Introduction to Bake: Streamlining Docker Builds
Summary
Bake is a tool built into the Buildx CLI that simplifies Docker builds by managing build configurations like CLI flags and environment variables. It promotes consistency across teams and handles complex configurations better than using command-line flags alone. Bake files can be written in HCL, YAML, or JSON, with HCL being the most flexible. The target properties in Bake files closely mirror the CLI flags for `docker build`. The document includes a simple example and compares a standard Docker build command with its Bake equivalent. The document also suggests next steps like defining and using targets in Bake, and referring to the Bake file reference for all target properties.