Naresh Chaurasia
Naresh Chaurasia

Reputation: 469

Not able to run nodejs as docker image on Windows using Docker Desktop

I am trying to run nodejs as docker image.

Code Location: https://github.com/Naresh-Chaurasia/Docker-for-Web-Developers/tree/master/Module4-Hooking_Your_Source_Code_into_a_Container/ExpressSite

I checkout the above code, and go to ExpressSite directory, and use the following command:

docker run -p 8080:3000 -v C:/tmp/ExpressSite:/var/www -w "/var/www" node npm start

On executing the above command i get the following error:

> [email protected] start
> node ./bin/www

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'express'
Require stack:
- /var/www/app.js
- /var/www/bin/www
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.<anonymous> (/var/www/app.js:1:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/var/www/app.js', '/var/www/bin/www' ]
}

I am using Docker Desktop on windows.

I am not much familiar with nodejs and learning dockers from Pluralsight course.

Can some one give pointers how to fix this issue.

Thanks.

Upvotes: 0

Views: 722

Answers (1)

Aditya Arora
Aditya Arora

Reputation: 303

You need to install the packages from package.json file into the docker container. You can create a dockerFile or you can run this first docker run -p 8080:3000 -v C:/tmp/ExpressSite:/var/www -w "/var/www" node npm install

I suggest you create a docker file like shown here

Upvotes: 2

Related Questions