build: support for named contexts(stages) by tonistiigi · Pull Request #904 · docker/buildx (original) (raw)

What were the main concerns?

The issue was with smth like docker --context=dockerctx buildx build --context foo=bar .. I agree --stage is not ideal as it is too Dockerfile specific while this can be easily supported by any frontend(eg. like --target).

I don't have good alternatives. I don't like --input and --source as that is not really the inputs, and --source is only one use case of the flag. The concept is more like a --define.

Trying to get my head around the docker-image example; does that mean that I can randomly override images without the Dockerfile having an indication that I can? Should it print a warning or error?

Yes, the caller has the ultimate control to configure the build with the cli flags. No warning/error. It is the same behavior as

So the following will build from a centos:7 image?

  1. yes
  2. no (ubuntu:latest not used)
  3. yes

I would expect the RUN echo "hello" > /hello to be called but doesn't seem like it.

With --stage ubuntu-base= you are overwriting the definition of that name. So the contents need to contain /hello file. If you wish to overwrite a base of that stage you would do --stage ubuntu:20.04=foo or define your stage like:

FROM ubuntu:20.04 AS ubuntu-base
FROM ubuntu-base AS ubuntu-build
RUN ...

FROM
COPY --from=ubuntu-build

For the cache comment, make a separate reproducer with clean buildx create cycle. I'm not sure if it is related.