I have several clients where some of them have shared files (types, components etc') the structure is as follows:
Project
|
+-- clients
| |
| +-- common1
| |
| +-- app1
| |
| +-- more_apps
| | |
| | +-- common2
| | +-- app2
| | +-- app3
+-- server
+-- docker-compose.yml
The docker compose file for app2 and app3 looks like this:
services:
app2:
build:
context: ./clients
dockerfile: ./more-apps/app2/Dockerfile
ports:
- "3012:3012"
container_name: app2
app3:
build:
context: ./clients/more-apps
dockerfile: ./app3/Dockerfile
ports:
- "3002:3002"
container_name: app3
and the docker file looks like this
FROM node:16-alpine
COPY . ./app
COPY ../../commom/stuff ./app
WORKDIR ./app
RUN npm install
RUN npm run build
RUN rm -rf ./app/stuff
EXPOSE 3012
CMD ["npm","run","app2"]
This obviously doesn't work. The copy in the Dockerfile is not working properly and even though the context is defined as the entire folder of clients
, it fails to copy the files in common1
. Same with the second app and the common2
file.
I also get an error that npm run can't be executed because package.json is not found in the app
directory. Only when I moved manualy the files into the relevant app
folder and updated the context to be only for that app I managed to execute the docker compose.
As far as I understood, the Dockerfile paths are always relative to the Dockerfile itself and not to the context, so I define the path as such. What am I missing?