The ability to build multiple Docker images from a single file is now available in our latest depot
CLI version. With the depot bake
command, you can now build multiple images from a single HCL, JSON, or Docker Compose file. It's a fantastic way to build all the images related to your application with a single build request to Depot.
What is Docker bake?
In a nutshell, bake
is a high-level build command that allows you to build multiple images from a single file via BuildKit. The bake
command allows you to issue a single build request with the file containing the image definitions to be built. All of the images get built concurrently against a single BuildKit builder.
With Depot, we are orchestrating BuildKit builders for every build you route to us. So a builder and its persistent cache are spawned for each architecture you request in a build. But a single Depot builder (i.e., a project) can handle multiple builds concurrently.
Build multiple images concurrently
Before Docker bake was supported, you would often need to run multiple depot build
commands to build multiple images with a single builder. A lot of our users have reached for a Makefile
to do this:
But this results in the images building serially. First, build the app image, then the DB, and finally, the cron image. It works, but you have to issue a separate build request for each image you want to build.
With bake
, you can build all these images concurrently with a single build request. To do it, you define a file that contains how all the images should be built; it can be written in an HCL, JSON, or Docker Compose file. Here is an example of a docker-bake.hcl
file that produces the same images as the Makefile
above:
The entire build definition from the Makefile
above is now contained in a single file. Bake files can specify all of the parameters you would pass to an image build, notice how the file above is using the platforms
and tags
parameters, much like --platform
and --tag
when running depot build
.
With this file, you can now run depot bake
to build all the images in the file:
What you see in the output is multiple images being built concurrently. So, for example, you can see that the app
image is being made for both linux/amd64
and linux/arm64
at the same time as the db
and cron
images are being built for both architectures.
Using bake with Docker Compose
You can also use Docker Compose files with depot bake
. This allows you to build multiple images from a single compose file. Here is an example docker-compose.yml
file that builds the same images as the docker-bake.hcl
file above:
This allows you to define a single file that contains multiple Docker images with multiple Dockerfiles and build them all concurrently with a single depot bake
command.
depot/bake-action
GitHub Action
In addition to the depot bake
command, we released depot/bake-action
GitHub Action that implements the same inputs and outputs as the docker/bake-action
.
Like our depot/build-push-action
, you can use GitHub's OpenID Connect tokens via a trust relationship, so your builds can authenticate with Depot projects without needing any static access tokens. Here is an example GitHub Action workflow that builds images from a docker-bake.hcl
file:
Conclusion
Building multiple images via depot bake
is a great way to speed up your image builds even more. With bake
, you can leverage BuildKit's ability to build multiple images concurrently and deduplicate work across multiple images specified in a single build request.
Define all the images that compose your application in a single HCL, JSON, or Docker Compose file and run depot bake
to build them all at once. No more waiting for each image to build one at a time. Instead, you can build them all concurrently on the same builder.
For those of you leveraging GitHub Actions, you can use the depot/bake-action
to build images from your file inside your existing Actions workflows. Just swap in depot/bake-action
for docker/bake-action
, and you're good to go.
If you're not using Depot, we offer a free tier to let you try things out in your existing workflows to see if we can make your image builds faster. We are the only remote container build service that offers native multi-platform image support, and we make caching a breeze because it's automatically persisted for you across builds. These two features usually make image builds 15x faster in CI environments.
Sign up today for our free trial and swap docker build
for depot build
to get instantly faster builds: https://depot.dev/sign-up.