Node-red error connecting to Redis

The issue is a lack of undersanding about scopes/contexts…
Localhost in a container is local to the container, not to the host the docker engine is running.

Since you use docker compose, you will have a default network created for you and the containers connected to it. This network should have a build in dns server. Though, it might become necessary to declare your own network and assign you containers to them in your docker-compose.yml. Not sure, I never worked with the default networks. For container to container communication use the servicename. You named your redis service redis, thus your node-red service needs to use redis:6379 to communicate with it. Container to container communication does not use published ports, they can call other containers ports directly without any restrictions.

If this is still not working… did you build the redis image yourself by any chance? If so, make sure when it startes the redis process, that it binds redis to 0.0.0.0:6379 and not localhost:6379.