I'm trying to run my nodeJS application on a docker.
The docker should contain Node.js
and an SQL
service.
docker-compose.yaml
:
version: '3.9'
services:
microsoft_sql_db_container:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: microsoft_sql_db_container
environment:
- MSSQL_SA_PASSWORD=Abcd1234!
- ACCEPT_EULA=Y
- MSSQL_AGENT_ENABLED=true
ports:
- 1433:1433
networks:
- dashboard_network
volumes:
- microsoft_sql_db_data_container:/var/opt/mssql
backend:
container_name: backend
build:
context: ../
dockerfile: ./UserManagementApi/docker/Dockerfile
ports:
- 3000:3000
restart: always
depends_on:
- microsoft_sql_db_container
networks:
- dashboard_network
volumes:
- type: bind
source: ./UserManagementApi/src
target: /app/user-management/src
- /app/user-management/node_modules
volumes:
microsoft_sql_db_data_container:
networks:
dashboard_network:
driver: bridge
Dockerfile
:
FROM node:16.14.0
RUN npm i -g [email protected]
WORKDIR /app
RUN mkdir userManagement
WORKDIR ./userManagement
COPY ./UserManagementApi/package.json ./
RUN pnpm i
COPY ./UserManagementApi/ .
CMD ["pnpm", "start:dev"]
When I'm navigation to the app/node_modules/ inside the docker image, I see all the packages.
Although, when I'm catting some random package - the package seems to be empty.
Thus, I'm receiving the following error when I'm running the image:
Error: Cannot find module '/app/userManagement/node_modules/@nestjs/cli/bin/nest.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
ELIFECYCLE  Command failed with exit code 1.
My question is, the copy of the nude_module seems to work fine, but the NPM i
seems to not work as expected.
Thanks in Advance for any help!
I think you may have to switch your workdir to UserManagementApi before running command "pnpm i" so that package.json is visible