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.
Subscribe to my newsletter!
You'll get notified via e-mail when new articles are published. I mostly write about Docker, Kubernetes, automation and building stuff on the web. Sometimes other topics sneak in as well.

Your e-mail address will be used to send out summary emails about new articles, at most weekly. You can unsubscribe from the newsletter 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.