Build A File With Docker Build

Posted on

I helped a colleague build a docker container that during the docker build phase would just produce a file, as there is no need for a full on image. To do this, we need a multi image container

  FROM --platform=linux/aarch64 debian as builder
  #<do things>
  FROM scratch as artifact
  COPY --from=builder /full/path/to/file/to/copy /path/on/host

And then you can build it like so.

docker build --target artifact --output type=local,dest=. .

You then get a file from the build process on your host. This can be useful for shared libraries.