A buildx_buildkit container appears during docker build and its name is already taken
buildx_buildkit_mybuilder0Short answer
That container is the BuildKit daemon of a buildx builder that uses the docker-container driver. Its name is buildx_buildkit_ plus the builder name and node index. A name clash means an older copy was left behind, often after removing the builder with --keep-daemon. Remove the stale builder and container, or switch to the default builder.
Fix it fast
1Find out which cause you have
List the builders buildx knows about, and the BuildKit containers Docker has. The current builder is marked with a star; a container with no matching builder is the stale one.
docker buildx ls docker ps -a --filter name=buildx_buildkit2Match what you see, then jump to its fix
- 1
docker buildx ls does not show the builder, but docker ps -a still lists buildx_buildkit_<name>0.A BuildKit container was left behind by an earlier builderFix - 2
docker build pulls moby/buildkit and starts a container you never asked for.A docker-container builder is the current builderFix - 3
A builder you recreated with the same name behaves as if it still had its old cache.A recreated builder reuses the state of the old oneFix
- 1
What does the error look like?
buildx_buildkit_mybuilder0moby/buildkit:buildx-stable-1
Cause 1 of 3
A BuildKit container was left behind by an earlier builder
1Check
docker buildx rm has a --keep-daemon option that leaves the BuildKit daemon running after the builder is removed, so the container stays and keeps its name.
docker ps -a --filter name=buildx_buildkit --format '{{.Names}} {{.Status}}'2Fix
Remove the stale container, then create the builder again. Remove a builder normally, without --keep-daemon, next time.
docker rm -f buildx_buildkit_mybuilder0
docker buildx create --name mybuilder --driver docker-container --use3Verify
Run the build again; no name conflict is reported.
docker buildx build -t test-image --builder mybuilder .Confirmed by docs.docker.com
Cause 2 of 3
A docker-container builder is the current builder
1Check
The docker-container driver runs BuildKit in its own container, and by default buildx pulls moby/buildkit for it. The default driver of docker buildx create is docker, which does not need that container.
docker buildx ls2Fix
If you do not need multi-platform builds or cache export, switch to the default builder and remove the extra one.
docker buildx use default
docker buildx rm mybuilder3Verify
The star in the builder list sits on default, and the build no longer starts a container.
docker buildx lsConfirmed by docs.docker.com
Cause 3 of 3
A recreated builder reuses the state of the old one
1Check
With --keep-state the BuildKit state stays in a volume named like buildx_buildkit_<name>0_state, and a builder recreated with the same name reuses it.
docker volume ls --filter name=buildx_buildkit2Fix
Use a new builder name, or remove the state volume if you want a clean start.
docker buildx rm mybuilder
docker volume rm buildx_buildkit_mybuilder0_state3Verify
Create the builder again and run a build; the cache starts empty.
docker buildx create --name mybuilder --driver docker-container --bootstrapConfirmed by docs.docker.com
How do I stop it coming back?
- Remove builders with docker buildx rm and leave out --keep-daemon and --keep-state unless you need them.
- Give each builder a clear --name instead of relying on generated names.
- In CI, create the builder in the same job that uses it, and remove it at the end.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A dev container port does not open in the browser when Docker runs on a remote host
If your application only accepts calls from localhost, it will reject connections from published ports
Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.
3 causes, each with a fix