buildx
buildx copied to clipboard
`buildx bake` runs past the next `FROM` statement, unlike `docker build`
Looks like if you've got a Dockerfile with multiple stages, there is severely different behavior vs docker build, even in DOCKER_BUILDKIT=1 mode.
docker build --target starts at FROM ... AS target and builds until *the next FROM.
docker buildx bake starts at the FROM ... AS target and executes till the end of the file!
Here's a minimal repro:
https://github.com/nickatsegment/repro-buildx-bake-vs-build-dockerfile
$ ./test.sh 2>&1 | grep -E '^(FAIL|PASS):'
PASS: docker-build-repro-v1
PASS: docker-build-repro-v2
FAIL: docker-buildx-bake-repro-v1 actual v2 != expected v1
PASS: docker-buildx-bake-repro-v2
Is this intended? Am I doing something silly? Seems unlikely that I'm the first person to hit this.
Your link is 404 . Bake and buildkit build are identical. DOCKER_BUILDKIT=0 is different and always executes commands from the beginning of the Dockerfile, even if --target never needs them.
My bad, it was set to private. Fixed. Please take another look.
The relevant part is not where it starts, it's that it doesn't stop at the next target apparently.
You are not setting the target = "" in the bake file.
OHHHH. I guess I assumed that the target stanza did that automatically? Kind of confusing that there are two kinds of target?
There's no real mention of that keyword in https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md AFAICT? Maybe this is just a docs problem. WDYT?
It is mentioned in the supported fields, but yes it could be made more clear. Could define all the fields separately and document the data type and what docker build flag they correspond to.
There are no examples of it being used, so it's easy to miss. Plus the fact that it's an overloaded term, it's ungreppable.
An example of a docker-bake.hcl pointing at different targets in a single Dockerfile would go a long way. I think that's a pretty common use case, at least in my org, and I'm guessing a usual path to build bake.
Just my 2c from a UX perspective: I guess I'm finding the idea that a buildx bake target is a separate object from a docker build target pretty jarring. Probably too late to do anything about.