I set up a monorepo project with 3 packages
./project1
./project2
./project3
./shared
Each project has it’s own dockerfile and docker compose file
I used npm link to use the shared folder and add this in each package.json :
depedencies:{ "@my-shared/types": "file:../shared" }
and then I can import like this :
import { stuff } from '@my-shared/types';
For example if I run the command "npm run dev" in my project1 (which is a node api) Everything is working fine ! Unless… i’m using docker. If I run the command "docker compose up" in the ./project1 folder then I get error because it can’t find my shared folder.
This is my dockerfile :
FROM node:lts-slim
ENV TZ=Europe/Paris
ADD . /app/
WORKDIR /app
RUN npm install
EXPOSE 3001
CMD npm run dev
And this is my docker-compose :
services:
mongo:
image: mongo
container_name: mongodb
restart: always
volumes:
- dbdata:/data/db
networks:
- api-net
command: mongod --quiet --logpath /dev/null
environment:
- TZ=Europe/Paris
my-api:
build: .
image: my-api
restart: always
ports:
- 3001:3001
volumes:
- .:/app
depends_on:
- mongo
networks:
- api-net
environment:
- TZ=Europe/Paris
networks:
api-net:
driver: bridge
volumes:
dbdata:
I guess I just need to add the folder but I can’t figure it out how.
Thank you for your help
2
Answers
I solved it,
in my docker-compose.yml in the volume section I added :
Thank you for your help
For your apps to get the shared modules you need to include them in the volumes section of your app like so: