I'm building two microservices and dockerizing them. I have a folder that contains a script (PackageA) which I need in both services (ServiceA & B). My folder structure is as following:
Root
|
|--Docker
|--ProjectA
|-docker-compose.yml (builds ServiceA & ServiceB)
|--Services
|--PackageA
|-src
|-index.js
|-package.json
|--ServiceA
|-src
|-index.js
|-Dockerfile
|-package.json
|--ServiceB
|-src
|-index.js
|-Dockerfile
|-package.json
My docker-compose.yml:
version: '3'
networks:
mynetwork:
services:
servicea:
build: ./../../Services/ServiceA
container_name: servicea
ports:
- ...
networks:
- mynetwork
serviceb:
build: ./../../Services/ServiceB
ports: serviceb
- ...
networks:
- mynetwork
In both services th Dockrfile looks like this:
FROM node:16
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
COPY . ./
EXPOSE ...
CMD [ "node", "index.js" ]
So my question is: Could I dockerize also PackageA and create a volume with its content, and then using that volume in ServiceA & B? How could I share volumes between containers?