(SOLVED) Docker-Stack: Node-Red to access html://anothercontainer:port/snapshot.jpg

Hi there,

I am having a problem that is driving me crazy. Just now :sweat_smile:

I do have a working setup of two docker container running in the same network (nr_default) started via docker-compose:

  1. nodered - port 1880:1880
  2. getcam - port 8844:80

(getcam grabs one snapshot.jpg per second from a webcam's rtsp stream and provides this file via lighttpd)

What I can do:

  1. I can access the snapshot via http://ip_docker_host:8844/snapshot.jpg, both, from nodered flows and from external web browser

  2. I can also jump into the running nodered container and download the snapshot with curl -O http://getcam:80/snapshot.jpg; name resolution of getcam is provided by Docker itself

What I can't do:

I would like to close most ports of my docker stack and therefore replaced http://docker_host_ip:external_port with http://container_name:internal_port in below attached flow. But this doesn't show anything. Although the nodered container in principle is able to resolve getcam:80 as mentioned above. Weird.

Any hint to the right direction would be highly appreciated. Thanks.

[{"id":"2b768930.6f677e","type":"inject","z":"fa03549d.e12a88","name":"","topic":"","payload":"<html><img ng-src=\"\"></html>","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":180,"y":340,"wires":[["94969a6e.b0dd1"]]},{"id":"94969a6e.b0dd1","type":"function","z":"fa03549d.e12a88","name":"","func":"return {\n    template: msg.payload\n};","outputs":1,"noerr":0,"x":310,"y":340,"wires":[["d7d97ed9.b8d0a8"]]},{"id":"d7d97ed9.b8d0a8","type":"ui_template","z":"fa03549d.e12a88","group":"6c1d575b.2dfa78","name":"CAM","order":1,"width":"3","height":"2","format":"","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":430,"y":340,"wires":[["9835124d.4afbf"]]},{"id":"9835124d.4afbf","type":"debug","z":"fa03549d.e12a88","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":340,"wires":[]},{"id":"6c1d575b.2dfa78","type":"ui_group","z":"","name":"Test","tab":"3e818533.347cba","disp":true,"width":"6","collapse":false},{"id":"3e818533.347cba","type":"ui_tab","z":"","name":"Test","icon":"dashboard","disabled":false,"hidden":false}]

OK. One step further ...

On the dashboard pictures get embedded with the very same address, that I put into the flow. Consequently they are not shown if I referred nodered to the docker-internal container-name. Latter does not resolve for an "external" dashboard viewer since they do not have access to the docker internal DNS service.

Now I need to find a way to overcome this barrier :slight_smile:

Still open for tips.

For the sake of completeness:

a) Don't give up. Take a break. Try a different perspective. ... this quite often helps to find a solution :joy:

b) The solution is:

  • docker-compose.yml

           - ./data/nodered/:/data/
          - ./data/nodered/snapshot/getcam:/tmp/www/
  • settings.js

    httpStatic: '/data/snapshot/',

  • http-address in the flow

    < html> < img ng-src='/getcam/snapshot.jpg'></ html>

Note: I have choosen .data/nodered/snapshot/getcam1; .data/nodered/snapshot/getcam2; .data/nodered/snapshot/getcam3 for my various rtsp-cams. With this I can reference to the individual cam in each flow's http-address correspondingly.

Thanks for listening to my self-learning-and-talking-exercise :rofl:


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