一、拉取官方5.0.3鏡像
[root@localhost ~]# docker pull redis:5.0.3
下載完成
[root@localhost ~]# docker pull redis:5.0.3
5.0.3: Pulling from library/redis
f7e2b70d04ae: Pull complete
421427137c28: Pull complete
4af7ef63ef0f: Pull complete
b858087b3517: Pull complete
2aaf1944f5eb: Pull complete
8270b5c7b90d: Pull complete
Digest: sha256:4be7fdb131e76a6c6231e820c60b8b12938cf1ff3d437da4871b9b2440f4e385
Status: Downloaded newer image for redis:5.0.3
二、創(chuàng)建掛載目錄
1、創(chuàng)建掛載文件夾
[root@localhost ~]# mkdir -p /root/redis/data /root/redis/conf
[root@localhost ~]# cd redis/
[root@localhost redis]# ls
conf data
2、創(chuàng)建redis.conf
在/root/redis/conf目錄中創(chuàng)建文件 redis.conf
顯示目錄
[root@localhost redis]# cd conf/
[root@localhost conf]# ls
[root@localhost conf]# touch redis.conf
[root@localhost conf]# ls
redis.conf
[root@localhost conf]#
三、創(chuàng)建redis 容器
docker run -d --name redis -p 6379:6379 -v /root/redis/conf/redis.conf:/redis.conf -v /root/redis/data:/data redis:5.0.3 redis-server --appendonly yes
參數(shù)說明:
-d 后臺(tái)運(yùn)行
-p 端口映射到主機(jī)的端口
-v 將主機(jī)目錄掛載到容器的目錄
redis-server --appendonly yes : 在容器執(zhí)行redis-server啟動(dòng)命令,并打開redis持久化配置
1、啟動(dòng)redis
啟動(dòng)中報(bào)錯(cuò)如下:
[root@localhost ~]# docker run -d --name redis -p 6379:6379 -v /root/redis/conf/redis.conf:/redis.conf -v /root/redis/data:/data redis:5.0.3 redis-server --appendonly yes
9bc537c19ff0ad76727b5215da8cba4223c5ff97f1d9a53585d573ca71fd8c0c
docker: Error response from daemon: driver failed programming external connectivity on endpoint redis (fa297144f8d0c958288bb35a94ffbec545d348f2ff9f55a5b573f3d9a0354ace): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 6379 -j DNAT --to-destination 172.17.0.3:6379 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
說明: docker服務(wù)啟動(dòng)時(shí)定義的自定義鏈DOCKER由于某種原因被清掉
重啟docker服務(wù)及可重新生成自定義鏈DOCKER
解決方案:
第一步、重啟docker;
第二步、啟動(dòng)容器;
systemctl restart docker
docker start foo
2、容器創(chuàng)建成功,啟動(dòng)redis容器
1、啟動(dòng)失敗問題:?jiǎn)?dòng)容器就會(huì)出現(xiàn)iptables: No chain/target/match by that name出錯(cuò)
粗暴解決方案
重啟docker
2、正常啟動(dòng)啟動(dòng)顯示
![](/d/20211016/dbcf7360b33472a24597aa33d884eaac.gif)
四、客戶端連接
我用的 RedisDesktopManager
![](/d/20211016/e1574db4a24e48905c9a47b03d137ae8.gif)
![](/d/20211016/1b7a94494f2463251b029fbebc163353.gif)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。