在Docker中更改Node_RED设定setting.js过程

在Docker中部署了Node-RED,但是没有登录界面,经查询发现是https://nodered.org/docs/configuration所列出问题

但是,在DOcker安装的WEbui,portainer console中没有setting.js,所以网上搜索了一下,找到一下答案

You should not change the copy of settings.js in /usr/src/node-red this is the default and should be left alone. Also editing this file after starting the container will not work as it is copied to the userDir the first time Node-RED is started.

If you want to include your own version you should mount it into the /data directory as this is the userDir for the system when running.

You can use the docker -v option to mount a local copy of the file into the container.

docker -v /path/to/settings.js:/data/settings.js ...

shareimprove this answer

edited Feb 5 at 11:40

answered Feb 4 at 18:54

hardillb

26.2k73564

  • Ok, I will try to mount it on userDir. "You should not change the copy of settings.js in /usr/src/node-red this is the default and should be left alone. Also editing this file after starting the container will not work as it is copied to the userDir the first time Node-RED is started." For this, there is no default copy of setting.js file, this file don't exist inside the continer – Martina Pesca Bellio Feb 5 at 11:40 

  • It doesn't matter where the default is in the container (it will probably actually be under /usr/local/lib/node_modules/node-red), you should not be modifying it anyway. just mount your own version into /data which is the userDir (equivalent to ~/.node-red normally) – hardillb Feb 5 at 11:47

#但是实际上 这个setting.js文件在哪里呢?

开始我真的信了网上的内容,但是我进入node-red官方github后,发现了他的目录结构

node-red/packages/node_modules/node-red/

重新返回docker的webui,portainer里,打开console,root身份进入(请注意灰色的root只是提示还是要输入root),然后找到了setting.js文件目录:

root@4fg4a35bz918:/usr/src/node-red/node_modules/node-red#

然后开始安装编辑器,是的,得自己拉下来,小白白最爱nano

执行之后告诉我E: Unable to locate package nano

好的,apt-get update,然后就好了

终于进去了,可以修改参数了

在Docker中更改Node_RED设定setting.js过程_第1张图片

## 我主要修改的就是用户登录

但是我发现这种方式刷新还是太慢了,字都重叠了。直接ssh然后

sudo docker exec -it {container——name} bash

用伪终端进入docker进行编辑settings.js,进入后发现

adminAuth全部被注释,所以没有权限界面显示。

在Docker中更改Node_RED设定setting.js过程_第2张图片

将“//” 删除,就可以启用Node-RED权限分级功能。密码是MD5的password,就是这几个字符就是登录密码。

然后,没有任何变化。小白毕竟是小白,注意,我的工作目录是/usr/src/node-red/,我想当然的就去找settings.js。

其实分析一下逻辑关系就知道,我工作在Docker环境下,也就是虚拟机下,那么我进入的虚拟环境里面只能有Node-RED全部内容,所以我应该退到最后根目录,然后我看到了

在Docker中更改Node_RED设定setting.js过程_第3张图片

这才是Node-RED的工作目录全貌,进入data目录,后看到了真正需要修改的settings.js然后一切就正常了

在Docker中更改Node_RED设定setting.js过程_第4张图片

 计算新的密码,需要以下命令

node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here

计算出的字符串 替换

你可能感兴趣的:(在Docker中更改Node_RED设定setting.js过程)