Docker安装官方Redis镜像并启用密码认证
参考:docker官方redis文档
1.有特殊版本需求的可以查看redis镜像tag版本
3.2.11,3.2,3(3.2/Dockerfile) 3.2.11-32bit,3.2-32bit,3-32bit(3.2/32bit/Dockerfile) 3.2.11-alpine,3.2-alpine,3-alpine(3.2/alpine/Dockerfile) 4.0.9,4.0,4,latest(4.0/Dockerfile) 4.0.9-32bit,4.0-32bit,4-32bit,32bit(4.0/32bit/Dockerfile) 4.0.9-alpine,4.0-alpine,4-alpine,alpine(4.0/alpine/Dockerfile)
2.选择最新版latest
dockerpullredis:latest
[root@localhost~]#dockerpullredis:latest latest:Pullingfromlibrary/redis 4d0d76e05f3c:Pullcomplete cfbf30a55ec9:Pullcomplete 82648e31640d:Pullcomplete fb7ace35d550:Pullcomplete 497bf119bebf:Pullcomplete 89340f6074da:Pullcomplete Digest:sha256:166788713c58c2db31c41de82bbe133560304c16c70e53a53ca3cfcf35467d8a Status:Downloadednewerimageforredis:latest
3.启动容器并带密码
dockerrun--nameredis-test-p6379:6379-d--restart=alwaysredis:latestredis-server--appendonlyyes--requirepass"yourpasswd"
-p6379:6379:将容器内端口映射到宿主机端口(右边映射到左边)
redis-server–appendonlyyes:在容器执行redis-server启动命令,并打开redis持久化配置
requirepass“yourpasswd”:设置认证密码
–restart=always:随docker启动而启动
4.查看容器
dockerps
[root@localhost~]#dockerps CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES a126ec987cferedis:latest"docker-entrypoint.s…"4minutesagoUp4minutes0.0.0.0:6379->6379/tcpredis-test 3645da72ece6portainer/portainer"/portainer"7daysagoUp7days0.0.0.0:9000->9000/tcpsharp_lovelace 118ba79de20ahwdsl2/ipsec-vpn-server"/opt/src/run.sh"12daysagoUp12days0.0.0.0:500->500/udp,0.0.0.0:4500->4500/udpl2tp-vpn-server 848fdba6de60kylemanna/openvpn"ovpn_run"12daysagoUp12days1194/udp,0.0.0.0:1194->1194/tcpopenvpn a273504f9646mysql:5.6.38"docker-entrypoint.s…"8weeksagoUp5days0.0.0.0:3306->3306/tcpmysql5.6.38
redis容器的id是a126ec987cfe
5.查看进程
ps-ef|grepredis
[root@localhost~]#ps-ef|grepredis polkitd2654726535014:58?00:00:00redis-server*:6379 root2661026432015:05pts/000:00:00grep--color=autoredis
6.进入容器执行redis客户端
dockerexec-ita126ec987cferedis-cli-a'yourpasswd'
[root@localhost~]#dockerexec-ita126ec987cferedis-cli-h127.0.0.1-p6379-a'yourpasswd' 127.0.0.1:6379>ping PONG 127.0.0.1:6379>info #Server redis_version:4.0.9 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:d3ebfc7feabc1290 redis_mode:standalone os:Linux3.10.0-693.21.1.el7.x86_64x86_64 ...
-h127.0.0.1:默认不加为-h127.0.0.1
-p6379:默认不加为-p6379
或者连接的时候不带密码,如下:
[root@localhost~]#dockerexec-ita126ec987cferedis-cli 127.0.0.1:6379>ping (error)NOAUTHAuthenticationrequired. 127.0.0.1:6379>auth'yourpasswd' OK 127.0.0.1:6379>ping PONG 127.0.0.1:6379>info #Server redis_version:4.0.9 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:d3ebfc7feabc1290 redis_mode:standalone os:Linux3.10.0-693.21.1.el7.x86_64x86_64 arch_bits:64
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。