如何使用 windows 在 docker 中 运行 Node-Red

how to run Node-Red in docker using windows

我在windows中使用这个命令 我其实不知道node_red_data在哪里

docker run -it -p 1882:1880 -v node_red_data:/data nodered/node-red

我得到了以下错误。

npm ERR! code EJSONPARSE
npm ERR! file /usr/src/node-red/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/.npm/_logs/2021-01-26T11_44_30_912Z-debug.log

这也是我的日志文件 此文件是在我的 node_red_data 文件夹

中自动创建的
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   '--no-update-notifier',
1 verbose cli   '--no-fund',
1 verbose cli   'start',
1 verbose cli   '--cache',
1 verbose cli   '/data/.npm',
1 verbose cli   '--',
1 verbose cli   '--userDir',
1 verbose cli   '/data' ]
2 info using npm@6.14.10
3 info using node@v10.23.1
4 verbose config Skipping project config: /usr/src/node-red/.npmrc. (matches userconfig)
5 verbose stack Error: Failed to parse json
5 verbose stack Unexpected end of JSON input while parsing near ''
5 verbose stack     at parseError (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:470:11)
5 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:105:26)
5 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:52:5
5 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:123:16
5 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
6 verbose cwd /usr/src/node-red
7 verbose Linux 4.19.128-microsoft-standard
8 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "--no-update-notifier" "--no-fund" "start" "--cache" "/data/.npm" "--" "--userDir" "/data"
9 verbose node v10.23.1
10 verbose npm  v6.14.10
11 error code EJSONPARSE
12 error file /usr/src/node-red/package.json
13 error JSON.parse Failed to parse json
13 error JSON.parse Unexpected end of JSON input while parsing near ''
14 error JSON.parse Failed to parse package.json data.
14 error JSON.parse package.json must be actual JSON, not just JavaScript.
15 verbose exit [ 1, true ]

有什么帮助吗?

嘿,您面临的问题源于安装卷 (-v ...),您需要传递一个有效的 Windows 路径作为参数。更多信息:Official Docker documentation

命令 运行 Node-RED 作为 Docker 容器:docker run -p 1880:1880 -it -v "<Path-on-your-Windows-OS>:/data" nodered/node-red

其中 <Path-on-your-Windows-OS> 例如C:\Users\<username>\Documents\node-red-docker

我刚刚制作了自己的 node-red 实例。我无法使用节点红色图像。

FROM node
WORKDIR /usr/src/node-red
RUN npm install -g --unsafe-perm node-red
CMD node-red