I am struggling to set docker compose with 2 apps (2 different docker files). I searched through documentation and other StackOverflow answers it seems like there are some similarities but still i cannot apply anything that works.
goal: set 2 apps that will talk with each other.
I am using:
docker-compose up -d
When in Project folder.
- Project:
- APP1
- SRC
- server.js
- dockerfile1
- SRC
- APP2
- app.js
- dockerfile2
- docker-compose
- APP1
dockerfile1
FROM node:14.15-alpine
WORKDIR /app1
COPY ./package.json ./package-lock.json ./
RUN npm install
RUN mkdir ./src
COPY ./src ./src
CMD ["node", "./src/server.js"]
dockerfile2
FROM node:14.15-alpine
WORKDIR /app2
COPY ./package.json ./package-lock.json ./
RUN npm install
COPY ./ ./
CMD ["node", "./app.js"]
docker-compose
version: "3.2"
services:
app1:
build:
context: .
dockerfile: ./app1/dockerfile1
ports:
- published: ${APP_PORT:-4000}
target: 4000
volumes:
- .:/app/
app2:
build:
context: .
dockerfile: ./app2/dockerfile2
ports:
- published: ${APP_PORT:-3000}
target: 3000
volumes:
- .:/app/
ERROR:
app1 | internal/modules/cjs/loader.js:883
app1 | throw err;
app1 | ^
app1 |
app1 | Error: Cannot find module '/app1/src/server.js'
app1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
app1| at Function.Module._load (internal/modules/cjs/loader.js:725:27)
app1| at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
app1| at internal/main/run_main_module.js:17:47 {
app1| code: 'MODULE_NOT_FOUND',
app1| requireStack: []
app1| }
Source: Docker Questions