参考链接:https://blog.csdn.net/weixin_45821811/article/details/116211724

    1. # 拉取镜像
    2. docker pull redis
    3. # 创建挂载配置文件
    4. mkdir -p /Users/zhangzj/docker/redis/data
    5. mkdir -p /Users/zhangzj/docker/redis/conf
    6. vim redis.conf
    7. ...
    8. # 启动redis容器
    9. docker run \
    10. --restart=always \
    11. --log-opt max-size=100m --log-opt max-file=2 \
    12. -p 6379:6379 \
    13. --name redis \
    14. -v /Users/zhangzj/docker/redis/conf/redis.conf:/etc/redis/redis.conf \
    15. -v /Users/zhangzj/docker/redis/data:/data \
    16. -d redis redis-server \
    17. /etc/redis/redis.conf \
    18. --appendonly yes \
    19. --requirepass a123456
    20. # 命令解析
    21. 1.--restart=always 总是开机启动
    22. 2.--log 设置log
    23. 3.redis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件,最终找到的是挂载的目录 /etc/redis/redis.conf,
    24. 也就是linux下的/Users/zhangzj/docker/redis/conf/redis.conf
    25. 4. --appendonly yes 开启redis持久化
    26. 5. --requirepass a123456 设置密码
    27. # 配置文件redis.conf
    28. protected-mode no
    29. port 6379
    30. tcp-backlog 511
    31. requirepass wangyihui123@
    32. timeout 0
    33. tcp-keepalive 300
    34. daemonize no
    35. supervised no
    36. pidfile /var/run/redis_6379.pid
    37. loglevel notice
    38. logfile ""
    39. databases 30
    40. always-show-logo yes
    41. save 900 1
    42. save 300 10
    43. save 60 10000
    44. stop-writes-on-bgsave-error yes
    45. rdbcompression yes
    46. rdbchecksum yes
    47. dbfilename dump.rdb
    48. dir ./
    49. replica-serve-stale-data yes
    50. replica-read-only yes
    51. repl-diskless-sync no
    52. repl-disable-tcp-nodelay no
    53. replica-priority 100
    54. lazyfree-lazy-eviction no
    55. lazyfree-lazy-expire no
    56. lazyfree-lazy-server-del no
    57. replica-lazy-flush no
    58. appendonly yes
    59. appendfilename "appendonly.aof"
    60. no-appendfsync-on-rewrite no
    61. auto-aof-rewrite-percentage 100
    62. auto-aof-rewrite-min-size 64mb
    63. aof-load-truncated yes
    64. aof-use-rdb-preamble yes
    65. lua-time-limit 5000
    66. slowlog-max-len 128
    67. notify-keyspace-events ""
    68. hash-max-ziplist-entries 512
    69. hash-max-ziplist-value 64
    70. list-max-ziplist-size -2
    71. list-compress-depth 0
    72. set-max-intset-entries 512
    73. zset-max-ziplist-entries 128
    74. zset-max-ziplist-value 64
    75. hll-sparse-max-bytes 3000
    76. stream-node-max-bytes 4096
    77. stream-node-max-entries 100
    78. activerehashing yes
    79. hz 10
    80. dynamic-hz yes
    81. aof-rewrite-incremental-fsync yes
    82. rdb-save-incremental-fsync yes