Learn how to enable BuildKit with Docker Compose for faster builds, efficient caching, and advanced Docker image optimization. Our Docker Live Support Team is always here to help you.
How to Enable BuildKit with Docker Compose
Building Docker images has come a long way. Developers today want better speed, caching, and control during image builds, and that’s where Enable BuildKit with Docker Compose comes into play. BuildKit is a feature included with the Docker daemon that changes how containers are built and packaged. It’s faster, smarter, and gives you more options during build time.

An Overview
What Makes BuildKit Different
BuildKit isn’t just a new feature; it’s a powerful upgrade to Docker’s builder. It allows parallel, incremental, and multi-stage builds, which means you spend less time waiting. It also supports build-time secrets and arguments, helping you fine-tune your build process. On top of that, BuildKit uses a modern image format for better image storage and distribution.
Before moving ahead, make sure your Docker version is 18.09 or above. If you’re using an older version, upgrade Docker first to take advantage of these capabilities.
Enabling BuildKit with Docker Compose
There are multiple ways to snable this and each serves a specific purpose depending on how you manage your Docker environment. Let’s go through them clearly.
Enable BuildKit via Docker Daemon Config
The first approach is by updating your Docker daemon configuration. You’ll need to set the BuildKit feature to true in your configuration file. Open or create /etc/docker/daemon.json and add this:
{
"features": {
"buildkit": true
}
}
Once done, restart the Docker service to apply the changes:
$ sudo systemctl restart docker
After restarting, BuildKit is ready to go. You can now use the docker build command with the –progress=buildkit flag or set the DOCKER_BUILDKIT environment variable.
Enable BuildKit in docker-compose.yml
Another simple method to Enable BuildKit with Docker Compose is by setting the environment variable inside your Docker Compose file.
Here’s how your docker-compose.yml should look:
version: '3.8'
services:
web:
build:
context: .
args:
DOCKER_BUILDKIT: 1
This configuration ensures that the web service uses BuildKit during builds. The Compose version 3.8 supports defining build arguments directly, and here, DOCKER_BUILDKIT: 1 triggers the BuildKit engine automatically.
Supercharge Your Docker Builds Today!

Enable BuildKit Using Export Command
Finally, you can Enable BuildKit with Docker Compose through the terminal by setting the environment variable manually. Run the following command before building your images:
$ export DOCKER_BUILDKIT=1
This command activates BuildKit for the current shell session. When you now build your services using:
$ docker-compose build
Docker Compose will automatically use BuildKit as the builder. Setting the variable to 1 turns BuildKit on, while 0 or leaving it unset disables it. By default, Docker still uses the legacy builder, so enabling this variable ensures you’re using the optimized build engine.
Why BuildKit is Worth Using
Once you Enable it, you’ll instantly notice how much smoother your builds become. BuildKit improves both flexibility and performance. It supports multi-stage builds, which reduce image size and save disk space on the server. Its caching and parallel build features cut down build times drastically.
Moreover, BuildKit’s architecture works efficiently with Docker’s ecosystem, making it easy to integrate into your existing workflow. Faster builds mean quicker testing, shorter release cycles, and better developer productivity.
Conclusion
In short, taking a few minutes to Enable BuildKit with Docker Compose can transform how you build and manage containers. It’s a small change that delivers big improvements, speed, efficiency, and reliability all in one move.
