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.
I don't think there's a way to create a container for two applications, and I don't think that's the right way to do it.
A container docker is created for a single application, and even for logs how to do with two applications? If you want to stop one or restart one ?
I think the right way to do it is docker-compose
and use somethink like:
docker-compose.yml:
And run:
or