【问题标题】:Redis Docker - Unable to connect from C# clientRedis Docker - 无法从 C# 客户端连接
【发布时间】:2015-07-09 08:14:15
【问题描述】:

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

docker run --name 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

我错过了什么?

【问题讨论】:

    标签: c# redis docker


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-24
      • 2019-09-29
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      相关资源
      最近更新 更多