Modify /etc/hosts in nodered container

I have a local OpenIAP installation where I have configured a nodered agent.
From NodeRed I need to make an http request to make a call to an API, but I get the error “RequestError: getaddrinfo EAI_AGAIN”, doing the curl query from inside the nodeRed container, I get the error “curl: (6) Could not resolve host” which confirms me that it is a DNS error.

Is there a configuration file where I can modify the /etc/hosts file of the nodeRed container and not lose the configuration if it restarts?

another question, is there any way to buckup the flows created in the nodeRed agent, I am afraid of losing the work done.

Regards :slight_smile:

I guess it’s possible if you really want to, but I would not recommend it. Docker has an internal DNS server that keeps track of running instances and for everything “outside” uses the host machine’s DNS server. So if you need to change anything, it should be on the host machine.

I understand that when you refer to “host machine” you mean the linux machine where the docker containers are running? On that machine I already had the entry added to /etc/hosts.
I have tried to add it also on the Windows machine, but Node-RED keeps returning the error “RequestError: getaddrinfo EAI_AGAIN.

Right now my scenario is:

  • Linux host machine where the containers are running with the entry in /etc/hosts.
  • Windows machine where the robots run with the entry in /etc/hosts.

But it keeps returning the error, I don’t know where I would have to put the entry for the container to know how to reach the URL if it is not in the Node-RED container itself.

So i was wrong, while typing a reply I wanted to google something to make sure i was right and I see, I was not …
To edit the host file on docker, you add

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

to the docker compose file

thank you very much for the info Allan.
The problem is that I have no control over how the Node-Red container is raised as it is an agent. I have tried adding the extra_hosts variables to the main “api” container in docker-compose in the hope that it will replicate the variables in the agent containers, but it does not.

In the docker-compose launched with the script “normal-up.sh” there is no configuration of the nodered agent container.

Yeah, good point, almost forgot about agents created. No, sorry, I don’t have a solution for that right now. I guess it could be interesting to add as a feature at some point, but it will take a while before I can move that up the list.

Can I ask, why do you need to add it to hosts? Why not just make the request by IP address, or add it to your local DNS server (or use your public DNS zone if you don’t have an internal DNS server)? It’s generally a bad idea to use /etc/hosts nowadays (not saying there aren’t use cases, but you should try to avoid it).

Edit: I vaguely remember needing to add something to a Docker install a few years ago on MacOS… I found a guide on how to set up a Dnsmasq so we did not need to “mess” with hosts files. I’m sure there is something similar for Linux.

I have tried to apply the idea you told me Allan, but to add the DNS server I also have to modify the /etc/resolv.conf file of the Node-RED container to add my external DNS server.

We have the same problem as to modify the /etc/hosts file, we don’t have the possibility to modify the docker-compose of the container because it is an agent. Or in this case if there is any solution?

Is there any documentation or any explanation of how openiap lifts the agent containers to see if we can add the configuration we need?

thank you very much for following up on this thread :slight_smile:

No, you use dns INSTEAD of updating hosts.
So you setup a dns server used by all your clients (outside docker) and servers (that has like the one that has docker installed ) and then you add the entry there.
If you ONLY need to use it on a single machine with docker installed, you could use Dnsmasq on the host.

Okay, thank you very much.

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