For anyone that is interested in something similar, I’ve found a workaround for now.
Using the LABEL command in my dockerfile I added a label to the build stage I’m interested in, then filter for it later:
FROM node as builder-stage
LABEL builder=true
FROM node as app-stage
LABEL builder=false
Now to filter, sort newest first, cut out the date, and take the top row:
docker images --filter “label=builder=true” --format ‘{{.CreatedAt}}\t{{.ID}}’ | sort -nr | head -n 1 | cut -f2
Note that it is important to remove the label in the next build stage.