I have a Dockerfile with multiple targets. For example:
FROM x as frontend
...
FROM y as backend
...
FROM z as runtime
...
COPY --from=frontend ...
COPY --from=backend ...
In order to build and tag the final image, I use:
docker build -t my-project .
To build and tag intermediary targets, I provide --target
argument:
docker build -t my-project-backend --target backend .
But is it possible to build a final image and tag all the intermediary images as well? In other words, the same as :
docker build -t my-project-frontend --target frontend .
docker build -t my-project-backend --target backend .
docker build -t my-project .
But with a single command?
I think a bit of explanation required. If use buildkit (export DOCKER_BUILDKIT=1
), then all independent targets are built in parallel. So it's simply faster than building them one by one.
And I need to tag every target to push them to a docker registry as well as final one.
Currently I'm building my images in CI without buildkit and I'm trying to speed up the process a bit.