Showing the Time Each Layer of Your Docker Image Build Takes

How to find out how long your Docker image build takes for each layer?

Measuring the total build time is quite straightforward - just add time in front of your docker build command.

You also don’t have to sit there with a stop-watch to time your layers. Here’s a simple way to get the time each layer you build:

Use the BuildKit buildx Command

BuildKit brings along a few useful features you can use out of the box starting with Docker 18.06.

It’s an alternative build backend to create Docker images, which is not the default at the moment. You can make use of it to show the duration of each layer build without making any changes to your setup.

Open a terminal in the directory where your Dockerfile is located, and perform a build, but instead of your usual docker build command, run it with docker buildx build.

So instead of:

$ docker build -t imagename .

You can use the following command to run your build with BuildKit:

$ docker buildx build .

The CLI output will show you how long each layer took to build. As the buildx build command requires a slightly different workflow, don’t expect to produce an image. However, you can use the time information to find out which layers are slowing your build down the most.

Sample intermediate BuildKit output.
Get updates
You will get emails when I publish something new or have something useful to share about making profitable digital businesses less brittle, less founder-dependent and easier to run.

Expect practical notes on backups, safer deploys, infrastructure as code, observability, documentation and automation. Usually no more than one email per week. You can unsubscribe at any time.

Für den Versand unserer Newsletter nutzen wir rapidmail. Mit Ihrer Anmeldung stimmen Sie zu, dass die eingegebenen Daten an rapidmail übermittelt werden. Beachten Sie bitte auch die AGB und Datenschutzbestimmungen .

vsupalov.com

© 2024 vsupalov.com. All rights reserved.