环境: VMware+CentOS7

前提: 防火墙处于开启状态

否则报错

0d4dabba317c026d2c15161d3948156304098e3bddf592067d74a690fd6b1e3f
docker: Error response from daemon: driver failed programming external connectivity on endpoint redis5 (621907508d82eabf869bb899076e11f68e70d41aa913ebb2f1a00517cca8bfa1):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 6379 -j DNAT --to-destination 172.17.0.2:6379 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)).
# 拉取镜像
docker pull redis:5.0.5
# 创建文件夹
mkdir /home/eric/redis/conf
mkdir /home/eric/redis/data
 

下载配置文件

# 修改配置文件
 
# 把 bind 注释掉或改为 0.0.0.0
bind 0.0.0.0
 
# protected-mode 改为 no
protected-mode no
 
# 注意: daemonize 一定不能设置为yes, 否则无法正常运行
daemonize yes
 
# 设置密码
requirepass 密码
 
# 键过期通知
notify-keyspace-events Ex
 
# 保存并退出
cd /home/eric/redis/
vim redis.sh
# 添加启动 redis 容器命令
docker run -itd --restart=always --privileged=true --name redis5 -p 6379:6379 -v /home/eric/redis/conf/redis.conf:/etc/redis/redis.conf -v /home/eric/redis/data:/data redis:5.0.5 redis-server /etc/redis/redis.conf --appendonly yes
# 保存并退出
sudo chmod 777 redis.sh
sh redis.sh

添加端口

sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent

关闭防火墙

#停止防火墙
sudo systemctl stop firewalld.service
#禁止防火墙开机启动
sudo systemctl disable firewalld.service