Img can't display in Node-red running in docker

Hi all, I have setup node-red in docker on ubuntu 16.04.6.
I have changed the settings.js (home/gaofei/.node-red) to

httpStatic: '/home/gaofei/img',

and I add a ui_template and config it as

<div class="c1">
<img src="/3.jpg" height="400" width="400" ><br/>
</div>

But the img can not be displayed successfully.

docker logs mynodered

> node-red-docker@1.0.6 start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"

17 May 08:35:18 - [info]

Welcome to Node-RED
===================

17 May 08:35:18 - [info] Node-RED version: v1.0.6
17 May 08:35:18 - [info] Node.js  version: v10.20.1
17 May 08:35:18 - [info] Linux 4.4.0-151-generic x64 LE
17 May 08:35:18 - [info] Loading palette nodes
17 May 08:35:19 - [info] Dashboard version 2.22.1 started at /ui
17 May 08:35:19 - [info] Settings file  : /data/settings.js
17 May 08:35:19 - [info] HTTP Static    : /home/gaofei/img
17 May 08:35:19 - [info] Context store  : 'default' [module=memory]
17 May 08:35:19 - [info] User directory : /data
17 May 08:35:19 - [warn] Projects disabled : editorTheme.projects.enabled=false
17 May 08:35:19 - [info] Flows file     : /data/flows.json
17 May 08:35:19 - [info] Server now running at http://127.0.0.1:1880/
17 May 08:35:19 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

17 May 08:35:19 - [info] Starting flows
17 May 08:35:19 - [info] Started flows
17 May 08:36:16 - [info] Stopping flows
17 May 08:36:16 - [info] Stopped flows
17 May 08:36:16 - [info] Starting flows
17 May 08:36:16 - [info] Started flows
17 May 08:36:25 - [error] [file in:read mp3] Error: ENOENT: no such file or directory, open '/img/1.mp3'

If just running node-red in WIN10 or Ubuntu , not installed in docker ,the img can show successfully.
I have tried to change the ui path in settings.js and it works,so it proves that the settings.js file I modified is the correct one.

Could you please give some advise ?

Thanks .

1 Like

Hi. I'm am by no means a docker expert but I'm fairly certain you can't simply access directories on the host.

Perhaps this would help?

Thanks for your reply. I use the command:
docker run -it -p 1880:1880 -v /home/gaofei/.node-red:/data --name mynodered nodered/node-red
So the host /home/gaofei/.node-red directory is bound to the container /data directory.

I also tried to copy img to /data/ directory or /home/gaofei/.node-red , still no effect.

Solved .

httpStatic: '/data/img',
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.