1、拉取镜像
docker pull redis:latest
如果拉取失败可以尝试下配置镜像源,具体参考如下,目前暂可以使用
Docker切换镜像源-CSDN博客
2、创建配置文件
mkdir /usr/local/redis/conf
vim redis.conf
bind 0.0.0.0
#protected-mode no
port 6379
tcp-backlog 511
# 登录密码
requirepass 123456
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
# 默认没有日志
logfile ""
# 指定日志输出位置
# logfile /var/log/redis/redis-server.log
databases 30
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
appendonly yes
appendfilename "appendonly.aof"
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-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
hz 10
aof-rewrite-incremental-fsync yes
3、执行镜像
docker run -p 6379:6379 --name redis --restart=always \
-v /usr/local/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /usr/local/redis/data:/data \
-d redis redis-server /etc/redis/redis.conf \
--appendonly yes --requirepass 123456