Redis Docker Container
Introduction
Redis is an in-memory data structure store, used as a database, cache, and message broker. Redis officially releases Docker container routinely. With the official containers, we probably don’t have to go through the Redis installation ever.
In this blog post, I would like to quickly discuss the Redis Docker container setups for both server and client.
Redis Docker Container
Redis Server
We first run a Redis server container by running the following command on our local computer.
1 | $ docker run --name redis-local-server -p 127.0.0.1:6379:6379/tcp -d redis:6.2.6 redis-server --save 60 1 --loglevel warning |
Redis Client
The Redis server container will run in detach mode in the background. Then, we create a Redis client container that connects to the Redis server container that we just created.
We are able to communicate with the Redis sever from the other container.
1 | $ docker run -it --rm --name redis-client --network host redis:6.2.6 redis-cli -h 127.0.0.1 -p 6379 |
Custom Redis Server
With the redis.conf
configuration file for Redis server customization, we will never have to install Redis server on our computer.
We prepared the following redis.conf
configuration file and placed it into the redis_config
directory.
1 | port 6380 |
Notice the port has been changed from the default 6379
to 6380
.
To start the Redis server container with our custom configuration file.
1 | $ docker run --name redis-local-custom-server -v $(pwd)/redis_conf:/usr/local/etc/redis -p 127.0.0.1:6380:6380/tcp -d redis:6.2.6 redis-server /usr/local/etc/redis/redis.conf |
The connection was successful from our Redis client container.
1 | $ docker run -it --rm --name redis-client --network host redis:6.2.6 redis-cli -h 127.0.0.1 -p 6380 |
References
Redis Docker Container