Pure Docker creates persistent Redis

preface

Before, after the server was bought, it used Docker to run an instance of Redis and put it there. Until some time ago, I found that Redis would delete all key values inexplinexplably, which may have been hacked — hence this article, hoping to simply configure a password protected one through Docker. Persistent Redis.

steps

First, we create a redis folder under /usr/local/ to store the redis configuration files and data

mkdir /usr/local/redis
mkdir /usr/local/redis/data
touch /usr/local/redis/redis.conf
Copy the code
  1. Writing configuration files
## appendonly yes #default: run daemonize as daemon. Appendfilename "appendonly. Aof "#default: Appendfsync everysec port 6379 # Bind 0.0.0.0 requirepass passwordCopy the code
  1. Write a docker directive

vim redis.sh

docker run -p 6379:6379 --name redis -v /usr/local/redis/redis.conf:/etc/redis/redis.conf # # to redis. Conf hanging on to the docker etc/redis directory - v/usr/local/redis/data: / data - d redis: 6.0 redis server/etc/redis/redis. Conf The append command runs the Redis server and specifies the configuration file you just mountedCopy the code
  1. usesh redis.shStart Redis and use itdocker psViewing the Running Status

If redis does not run, check the error message by docker logs redis

Configuring passwords Online

If you do not want to set the password through the configuration file for the enabled Redis, you can use the command

Config set requirepass [password] to configure the command online

In addition, it is worth mentioning that passwords configured by command are not synchronized to the redis.conf configuration file