By default, Redis does not accept external connections, even if they are from a subnet of its own like Docker containers. To work around this limitation, you can expand Redis' bind to listen on other IPs and apply authentication for this type of connection.
For the following changes, you can edit the redis.conf file using:
sudo nano /etc/redis/redis.conf
Example binds you can use:
bind 127.0.0.1 -::1 - Allows only localhost connections on IPv4 and IPv6bind 127.0.0.1 -::1 172.17.0.1 - Allows localhost connections on IPv4 and IPv6, and the default Docker IPbind * -::* - Allows ALL IPs to connect to Redis
Regardless of the bind, Redis allows localhost connections without authentication, but connections from different IPs, even a local IP like Docker's, require authentication. To work around this, you need to disable protected-mode by setting the following line:
protected-mode no
To apply the changes, run:
sudo systemctl restart redis-server
To monitor queries sent to Redis in real time, run:
sudo redis-cli monitor