Redis Docker – 无法从C#客户端连接

我是docker和redis的新手,我使用以下命令在docker上运行redis 3.0:

docker运行 – 名称redisDev -d redis

它似乎开始与港口连接6379很好:

docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b95c9402dd42 redis:3 "/entrypoint.sh redi 47 minutes ago Up 47 minutes 6379/tcp redisDev 

我试图用下面的代码连接:

  var sb = new StringBuilder(); var tw = new StringWriter(sb); ConnectionMultiplexer redis; try { redis = ConnectionMultiplexer.Connect("vb-haproxy01.verify.local", tw); } catch (Exception ex) { //Console.WriteLine(ex.Message); tw.Flush(); Console.WriteLine(sb.ToString()); return; } 

我得到以下错误:

 vb-haproxy01.verify.local:6379 1 unique nodes specified Requesting tie-break from vb-haproxy01.verify.local:6379 > __Booksleeve_TieBreak ... Allowing endpoints 00:00:05 to respond... vb-haproxy01.verify.local:6379 faulted: SocketFailure on PING vb-haproxy01.verify.local:6379 failed to nominate (Faulted) > UnableToResolvePhysicalConnection on GET No masters detected vb-haproxy01.verify.local:6379: Standalone v2.0.0, master; keep-alive: 00:01:00; int: Connecting; sub: Disconnected; not in use: DidNotRespond vb-haproxy01.verify.local:6379: int ops=0, qu=0, qs=0, qc=1, wr=0, sync=1, socks =2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=2 Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s) Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago resetting failing connections to retry... retrying; attempts left: 2... 1 unique nodes specified 

Linux防火墙设置:

 sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:6379 Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination 

我错过了什么?

问题是主机上的端口6379没有将端口6379转发到docker。 以下命令的“-p 6379:6379”解决了这个问题:

 docker run -d --name redisDev -p 6379:6379 redis