I only noticed that multiple build contexts were mentioned here when I decided to write the post.
Here is my service from docker-compose:
frontend: build: context: ./frontend additional_contexts: - configs=./configs dockerfile: Dockerfile
And here is my Dockerfile:
FROM node:18.16.1-alpine3.17 as builderRUN mkdir /frontendWORKDIR /frontendCOPY --from=configs ./.env.prod .
You can find more information about additional_contexts here:https://docs.docker.com/compose/compose-file/build/#additional_contexts
And there is information about Dockerfile and how build it with multiple context without docker-compose:https://www.docker.com/blog/dockerfiles-now-support-multiple-build-contexts/