I have project structure that look like this:
apps
--services1
--- here all the file of service1
--services2
--- here all the file of service2
libs
-- Here will have some files, needed by services1 and services2
packages.json
Dockerfile.service1
Dockerfile.service2
docker-compose.yml
in my Dockerfile.service1
then I do like this:
FROM node:12.17-alpine as builder
WORKDIR /build
COPY package.json yarn.lock ./
RUN yarn
COPY . .
RUN yarn build:services1
EXPOSE 3000
CMD [ "yarn", "start:services1"]
Dockerfile.service2
also having the same command
So right now my problem is:
Dockerfile.services1
and Dockerfile.services2
both will COPY
all the project file into the image, means that Service1Image
will contain files of apps/services2
file.
Soon, the project will have 50 services, inside apps
folder, therefore in order to build 1 docker image for 1 service, the image will contain files of 50 microservices.
Question:
Is it anyway to exclude folder in apps
folder excepts apps/services1
in Service1Image
? But it need to include libs
, packages.json
inside Service1Image
, and the same way to Service2Image
. Is it possible?
My attempt
FROM node:12.17-alpine as builder
WORKDIR /build
// I only copy `libs` `apps/services1`, is this right??
COPY package.json yarn.lock libs apps/services1 ./
RUN yarn
COPY . .
RUN yarn build:app-one
EXPOSE 3000
CMD [ "yarn", "start:app-one"]