Depending on how large your initial data set is and if your initial data doesn't change much, it may be easier to have your clean docker container load it on startup from a *.redis
file using redis-cli
(link).
Create your seed commands file (my-data.redis
):
SET key1 val1
SET key2 val2
...
...
Create a redis startup shell script (my-redis.sh
):
# start server in background and wait for 1 sec
redis-server --daemonize yes && sleep 1
# slurp all data from file to redis in memory db (note the dir)
redis-cli < /my-dir/my-data.redis
# persist data to disk
redis-cli save
# stop background server
redis-cli shutdown
# start the server normally
redis-server
Create a custom redis docker image with your shell script as CMD, something like this (a better solution would be to hack the entrypoint but who's got time for that?):
FROM redis:latest
COPY my-data.redis /my-dir/
COPY start-redis.sh /my-dir/
CMD ["sh", "/my-dir/my-redis.sh"]
Done. No external volumes or builder containers needed. Build and run:
docker build -t my-redis:latest .
docker run -p 6379:6379 my-redis:latest