In order to have multiple Dockerfiles at the root of your project, you can give them different filenames for organization.
my-project:
-- apps;
--- app-one
---- src
---- tsconfig.app.json
--- app-two
---- src
---- tsconfig.app.json
-- libs
-- package.json
-- Dockerfile.app-one
-- Dockerfile.app-two
To handle these Dockerfiles, you will need to execute custom scripts to build the specified application.
Dockerfile.app-one
FROM node:12.17-alpine as builder
WORKDIR /build
COPY package.json yarn.lock ./
RUN yarn
COPY . .
RUN yarn build:app-one
EXPOSE 3000
CMD [ "yarn", "start:app-one"]
package.json
"scripts": {
"build:app-one": "nest build app-one",
"build:app-two": "nest build app-two",
"start:app-one": "nest start app-one",
"start:app-two": "nest start app-two",
}
nest-cli.json
{
"projects": {
"app-one": {
"type": "application",
"root": "apps/app-one",
"entryFile": "main",
"sourceRoot": "apps/app-one/src",
"compilerOptions": {
"tsConfigPath": "apps/app-one/tsconfig.app.json",
"assets": []
}
},
"app-two": {
"type": "application",
"root": "apps/app-two",
"entryFile": "main",
"sourceRoot": "apps/app-two/src",
"compilerOptions": {
"tsConfigPath": "apps/app-two/tsconfig.app.json",
"assets": []
}
},
}
}
Then, denote the filename in your build/deploy tasks within your CI/CD pipeline.
.gitlab-ci.yml
image: docker:git
services:
- docker:dind
stages:
- build
build-app-one:
stage: build
script:
- docker build . -f Dockerfile.app-one
build-app-two:
stage: build
script:
- docker build . -f Dockerfile.app-two
If further information is required, refer to the documentation on NestJS monorepo architecture.