Running a Redis instance on Docker

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 --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). The CLI should now be visible and we can try sending some commands to our redis server.

Let's begin with a simple ping:
redis ping PONG

Setting a value to "mykey":
redis set mykey somevalue OK

Getting the value:
redis 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.

Happy coding!


Oskar Lind

I'm a front-end developer with over 10 years of experience in web development, e-commerce, SEO and web analytics. I'm also an experienced speaker, programming teacher and team leader.

Read More