I am running Node-RED on Docker, and I am trying to write data to MySQL on my localhost.
As host, I am using localhost (see picture)
I receive the error: connection refused
.
Which Host address should I use here? I don't quite understand the communication between the container and the local host.
localhost
always points to the TCP/IP stack that the program opening the connection is bound to.
Every Docker container has it's own TCP/IP stack so unless the database is running in the same container as Node-RED localhost
will not be the correct hostname for the database.
You have 3 choices
docker inspect [container-instance-name]
to find the IP address assigned to the database container and use that-p
option) then you can use the IP address of the host which normally defaults to 172.17.0.1
Edit:
To connect to the host machine then you can use host.docker.internal
on Docker for Windows and Docker for Mac (unfortunately the issue to fix this on Linux has been open for over 3 years).
You should also be able to use the IP address from point 3 above.