Here is my Dockerfile which is at the root of the nodejs application.
# Build from LTS version of node (version 12)
FROM node:12
# Create app directory
RUN mkdir -p /usr/src/app
# Define app diretory inside image
WORKDIR /usr/src/app
# package.json AND package-lock.json are copied where available
COPY package*.json /usr/src/app/
# install modules
RUN npm install
# Bundle app source
COPY . /usr/src/app
# Bind app to port 3000
EXPOSE 3000
# Command to run app
CMD [ "nodemon", "./bin/www" ]
Here is my docker-compose.yml file
version: '2'
services:
mongo:
container_name: mongo
image: 'mongo:3.4.1'
ports:
- "27017:27017"
backend-app:
container_name: school-backend
restart: always
build: ./server
ports:
- "3000:3000"
frontend-app:
container_name: angular-frontend
restart: always
build: ./angular-app
ports:
- "4200:4200"
I execute the command docker-compose up
Then I get this error
school-backend | Error: Cannot find module '/usr/src/app/nodemon'
school-backend | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
school-backend | at Function.Module._load (internal/modules/cjs/loader.js:842:27)
school-backend | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
school-backend | at internal/main/run_main_module.js:17:47 {
school-backend | code: 'MODULE_NOT_FOUND',
school-backend | requireStack: []
school-backend | }
In the Dockerfile, I copy the package.json to the working directory /usr/src/app\.
Then I do npm install which would install nodemon since it is declared in the package.json
But, why is the module given as absent?
nodemondoesn't add anything here and you could just run plainnode.