Redis is a fast, in-memory data structure store which can be used as a cache for your applications. It supports various data structures such as hashes, sets, bitmaps etc. Here’s how to launch a complete redis instance on docker, which can then serve your other applications.
Start by launching a redis server:
docker run --name my-redis -d redis
“-d” makes it run in the background, and “my-redis” is the name of the instance. “redis” is obviously the name of the docker image.
Your docker instance is now up and running on port 6379 (default for redis). It’s time to try it out using the redis client (redis-cli):
docker run -it --link my-redis:redis redis redis-cli -h redis -p 6379
The “–link” option links the redis-cli container to the redis server container. We then specify the image name (redis-cli), hostname (redis) and the port (-p). Since we added “-it” as an option, the CLI should now be visible and we can try sending some commands to our redis server:
redis 127.0.0.1:6379> ping PONG redis 127.0.0.1:6379> set mykey somevalue OK redis 127.0.0.1:6379> get mykey "somevalue"
You can now go ahead and link your other applications to the redis server, and use it as a fast and flexible storage.