1.docker pull redis:5.0.7 #拉取镜像
2.docker images #查看本地镜像
3. 修改配置文件(配置文件可去官网下载:http://download.redis.io/redis-stable/redis.conf)
bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
protected-mode no #默认yes,开启保护模式,限制为本地访问
daemonize no#默认no,改为yes意为以守护进程方式启动。注意这里不要改成yes,就用默认的no,改为yes后台启动会导致容器无事可做自动退出
appendonly yes #redis持久化
requirepass 123456 #设置密码
4.执行命令:docker run -p 6379:6379 --name redis5.0.7 -v /home/redis/redis.conf:/etc/redis/redis.conf -v /home/redis/data:/data -d redis:5.0.7 redis-server /etc/redis/redis.conf --appendonly yes
5.docker exec -it 容器ID /bin/bash 进入容器