I am using docker-compose to create a redis container. However, I need it to start with some default key values. Is this possible?
1 Answer
You need to modify your DockerCompose file, You can also add from some file which contains key value but here is the simplest example that adds and get key in DockerCompose file.
version: '2'
services:
redis:
image: 'bitnami/redis:latest'
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '6379:6379'
command:
- /bin/sh
- -c
- |
nohup redis-server &
sleep 5
echo "adding some default key value"
redis-cli SET docker awesome
echo "Get docker key value"
redis-cli GET docker
# this will keep container running
tail -f /dev/null
-
Note that, in the possibility that the Redis server crashes, since it's not the main container process, Docker won't notice this. You have "a container that does nothing, that happens to also be running Redis" as opposed to "a container that runs Redis". The PostgreSQL entrypoint script, for example, goes to some lengths to do this correctly. Jul 8, 2019 at 1:01
-
-
1
-
But it starts the redis container in protected mode. How to disable protected mode here in this yaml file itself? Dec 7, 2020 at 14:38