Redis is known as BDS-licensed open-source and has the ability to store data structure in-memory. It is also used as a message broker, cache, and database. In today’s modern era, redis is used as a primary database. Redis acronym is Remote Dictionary Server, which is reckoned to be the fastest one. If you are using a WordPress website, then redis quite beneficial for you as help you improve the load time by speeding up the website. Whereas Docker Composer is designed to assist in defining and sharing applications that are multi-container. The best way to use redis is to connect it with the docker-compose that helps for local development to a web app as a cache. To set password in redis in docker compose is sometimes tricky.
Though it seems a complex task, it is not as tough as it seems. We are here to assist you in setting up the password in a simpler way. But before setting up a password, let’s check out how you can create a docker-compose file for redis
Set up Redis’s Docker-Compose File
You need to specify the path when using redis.confi file as well as redis data. The redis-server –requirepass is a command for specifying a password. Have a look at the code to set up the redis’s docker compose file
version: "3.2"
services:
redis:
image: "redis:alpine"
command: redis-server --requirepass sOmE_sEcUrE_pAsS
ports:
- "6379:6379"
volumes:
- $PWD/redis-data:/var/lib/redis
- $PWD/redis.conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
networks:
node_net:
ipv4_address: 172.28.1.4
# networking for the Redis container
networks:
node_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
Now that you know how to set it up, check out how to set a password
How to Set Password in Redis in Docker Compose
Setting up a password using docker-compose is quite simple as you can do it without any config file needs. The simple and normal way to use your redis image is:
redis:
image: 'redis:4-alpine'
ports:
- '6379:6379'
In order to set up the custom password, you just need to change the code a bit. This is what you can do
redis:
image: 'redis:4-alpine'
command: redis-server --requirepass yourpassword
ports:
- '6379:6379'
Use Of requirepass to Set Password
Another way to set up the password is through requirepass. Have a look at the code to set the password
docker run -d \
-h redis \
-e REDIS_PASSWORD=redis \
-v redis-data:/data \
-p 6379:6379 \
--name redis \
--restart always \
redis:5.0.5-alpine3.9 /bin/sh -c 'redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}'
Conclusion
In this post, we discussed how to set password in Redis in docker compose. We highlighted setting up docker compose for Redis and how you can simply set up a password. By following the above-mentioned tips, you can get set up the password easily.
I hope you find it helpful! I wish you a happy password setting!
For further assistance, you can write us in the comment section below.