我正在尝试在docker容器中的节点上运行这个hello world示例
https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30
这是我的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
成功构建容器后:
docker build . -t nano-node-hw
并运行它,我收到以下错误:
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
我在本地运行节点的笔记本电脑(Windows 10)上执行了相同的步骤并且没有任何问题..什么给了??