After you run redis as a container, you might want to use Redis Insight to look into your redis instance using GUI. With just redis container, you can use its CLI to check your redis instance. However, with redis insight, you need another image.
➜ docker exec -it redis redis-cli
127.0.0.1:6379> SET color red
OK
127.0.0.1:6379> GET color
"red"
➜ docker run -d --name redisinsight -p 5540:5540 redis/redisinsight:latest
23b7291abd7d848a1556b5520e3ae3f9e646f21e67d3d567ee73cdc819c382a0
You can access redis insight via http://localhost:5540/. However, you might not be able to connect your redis insight with redis if you use redis://default@127.0.0.1:6379 as the connection string of redis. This is because 127.0.0.1 or localhost refers to the redis insight container, not redis. We want redis insight to communicate with redis container. To fix this, change the server to redis, the container name (e.g., redis://default@redis:6379). redis is the hostname that’s why it works.
Now, the above change of connection string may already allow you to connect to it successfully. However, you may encounter Could not connect to redis:6379, please check the connection details.. This may be due to containers being in the default bridge network, which does not support automatic DNS resolution for container names. To resolve this, we need to create a user-defined bridge network, which supports automatic DNS resolution.:
- Create the docker network:
docker network create redis-net - Attach existing containers to the network:
docker network connect redis-net redis
docker network connect redis-net redisinsight
- Inspect the network. The container names should appear in the search result.
docker network inspect redis-net | grep Name
"Name": "redis-net",
"Name": "redis",
"Name": "redisinsight",
With that, you should be able to test the connection string successfully and add the database. The color key we set earlier should be visible in the browser.