Search code examples
dockernodeswindows-container

nanoserver: "Error: Cannot find module node.exe" in Docker


Trying to run Nodejs on MS Nanoserver Install success, but when I run "node app.js", I get this error

dockerfile

FROM microsoft/nanoserver


ADD https://nodejs.org/dist/v10.4.0/node-v10.4.0-win-x64.zip C:\\build\\node-v10.4.0-win-x64.zip

RUN powershell -Command Expand-Archive C:\build\node-v10.4.0-win-x64.zip C:\; Rename-Item C:\node-v10.4.0-win-x64 node


ENTRYPOINT C:\node\node.exe
RUN SETX PATH C:\node
RUN SETX PATH "%path%;C:\node"
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD [ "node.exe" , "app.js" ]
EXPOSE 8081 

Error:

Error: Cannot find module 'C:\app\node.exe'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
    at startup (internal/bootstrap/node.js:238:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

Solution

  • See the docs: https://docs.docker.com/engine/reference/builder/#known-issues-run. If you are using the ENTRYPOINT directive then CMD can pick that up:

    CMD ["app.js"]