Hi,
Problem solved.
I created a www directory and moved package.json
and index.js
into it.
I modified the package.json file as follows:
{
"name": "nodejs-app",
"dependencies": {
"express": "^4.17.0"
},
"scripts": {
"start": "node index.js"
}
}
I also modified the Dockerfile as below:
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./www/package.json /usr/src/app/package.json
RUN npm install
RUN npm update
COPY ./www /usr/src/app
EXPOSE 3000
The YAML file is as follows:
version: '3.9'
services:
nodejs:
container_name: Node
build:
context: .
dockerfile: Dockerfile
command: npm start
volumes:
- ./www:/usr/src/app
expose:
- "3000"
Finally:
Node |
Node | > docker-nodejs@1.0.0 start
Node | > node index.js
Node |
Node | server running on 3000