1. 拉取合适的redis镜像
- 搜索合适的redis镜像
~$ docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 12610 [OK]
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 61
redislabs/redisinsight RedisInsight - The GUI for Redis 95
redis/redis-stack-server redis-stack-server installs a Redis server w… 64
redis/redis-stack redis-stack installs a Redis server with add… 89
redislabs/rebloom A probablistic datatypes module for Redis 25 [OK]
- 拉取redis镜像,以官方提供的为例
~$ docker pull redis
2. 创建redis的配置文件目录和配置文件
- 创建数据目录和配置文件的目录,位置随意
$ mkdir -p ~/docker_env/redis_01/data
$ mkdir -p ~/docker_env/redis_01/conf
- 创建配置文件
从官网(http://www.redis.cn/download.html)下载radis安装包,解压后copy其中的radis.conf文件到上一步新建的配置文件目录。
或者在配置文件目录中创建radis.conf文件,文件中编辑:
# bind 0.0.0.0 是否只允许监听本地ip
protected-mode no #是否允许远程连接
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /数据持久化AOF和RDB保存路径
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
3.启动docker环境
~$ docker run --name redis_01 -p 6479:6479 -v ~/docker_env/redis_01/data:/data -v ~/docker_env/redis_01/conf/redis.conf:/etc/redis/redis.conf -it redis redis-server /etc/redis/redis.conf
- redis-server启动时需要指定redis.conf路径,否则会安装默认配置启动。
- 使用
docker ps
产看是否启动; - 查看容器日志。
~$ docker logs -t redis_容器名称/id
4. 测试
~$ redis-cli -h 127.0.0.1 -p 6479 -a 密码
- 连接成功后,可以使用CONFIG GET * 监测是不是和预设的redis.conf一致。
5. 参考
主要参考了以下两篇博客: