The latest docker 20.10.x release unlocks the buildx
subcommands
which allow for some sugar, like building something in a container
and dumping the result to your local directory in one command.
Dockerfile
FROM docker-registry.mycorp.com/debian-node:lts as builder
USER service
COPY . /opt/service
RUN cd /opt/service; npm install; npm run build
FROM scratch as dist
COPY --from=builder /opt/service/dist /
build with
docker buildx build --target=dist --output type=local,dest=$(pwd)/pages/ .
Here we build a page, copy the result with all assets from the /opt/service/dist
directory to an empty image and dump it into the local pages
directory.