1

I am trying to run this hello world example on node within a docker container

https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30

Here is my dockerfile:

#escape=`
FROM microsoft/nanoserver

ADD https://nodejs.org/dist/v8.11.1/node-v8.11.1-win-x64.zip C:\node-v8.11.1-win-x64.zip

RUN powershell -Command Expand-Archive C:\node-v8.11.1-win-x64.zip C:\; Rename-Item C:\node-v8.11.1-win-x64 node; `
SETX PATH C:\node;

SHELL ["powershell", "-Command"]

RUN mkdir hello-world; `
    cd c:\hello-world; `
    npm init -f; `
    (Get-Content C:\hello-world\package.json) | `
    ForEach-Object { $_ -replace 'index.js', 'app.js' } | `
    Set-Content C:\hello-world\package.json; `
    npm install express --save; `
    echo \""var express = require('express');\"" > app.js; `
    echo \""var app = express();\"" >> app.js; `
    echo \""app.get('/', function (req, res) {\"" >> app.js; `
    echo \""  res.send('Hello World!');\"" >> app.js; `
    echo \""});\"" >> app.js; `
    echo \""app.listen(3000, function () {\"" >> app.js; `
    echo \""  console.log('Example app listening on port 3000!');\"" >> app.js; `
    echo \""});\"" >> app.js; `
    del c:\node-v8.11.1-win-x64.zip

EXPOSE 3000

ENTRYPOINT node c:\hello-world\app.js

after building the container successsfully:

docker build . -t nano-node-hw

and run it, I get the following error:

PS C:\Users\user\Docker\Node> docker run -it -p 3000:3000 --name node-hello nano-node-hw
c:\hello-world\app.js:1
(function (exports, require, module, __filename, __dirname) { ??v
                                                              ^

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

I did these same steps on my laptop (Windows 10) running node locally and had no issues.. what gives??

emvee
  • 304
  • 4
  • 17

0 Answers0