'--target option of docker build command doesn't work in aws codeBuild

I use a multi stages docker build for my aws codeBuild to build my application. The shape of my docker file is :

FROM strapi/base:14-alpine AS dependencies
...

FROM strapi/base:14-alpine As liveProduction
ENV NODE_ENV="production"
COPY --from=dependencies /toto /toto
....

FROM strapi/base:14-alpine As liveDevelopment
ENV NODE_ENV="development"
COPY --from=dependencies /toto /toto
...

And to build my application for production, i use aws buildspect.yml and in this file i have the following comande :

docker build --no-cache --target liveProduction -t app-facej-backoffice .

This command doesn't work very well, because, all stages are executed with the following order : dependencies, liveProduction, liveDevelopment. In this case, i want only dependencies and liveDevelopment to be executed.

I would like to know what is the problem ? Why the --target option of docker build doesn't work in codeBuild?

Thanks.



Solution 1:[1]

Skipping build stages is a feature of buildkit that creates a dependency graph. This is the default in newer versions of docker, so either the release of docker doesn't have buildkit, or you need an environment variable (DOCKER_BUILDKIT=1) set to enable it:

DOCKER_BUILDKIT=1 docker build --no-cache --target liveProduction -t app-facej-backoffice .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BMitch