docker-compose: redis connection refused between containers
In your code localhost
from rq-worker1
is rq-worker1
itself, not redis
and you can't reach redis:6379
by connect to localhost
from rq-worker1
. But by default redis
and rq-worker1
are in the same network and you can use service name as a domain name in that network.It means, that you can connect to redis
service from rq-worker1
using redis
as a domain name, for instance: client.connect(("redis", 6379))
You should replace localhost
with redis
in config of rq-worker1
.