为什么我不能在主机上转发端口8500与领事图像?

我尝试在Mac转发8500端口上运行Consul映像进行简单testing。 我的命令来运行图像是:

docker run -it -p 8500:8500 consul agent -server -bootstrap 0.0.0.0

我不使用--net=host因为它不能在Mac上工作,所以我尝试转发8500。

当我尝试从我的Mac远程login连接立即closures:

 user$ telnet localhost 8500 Trying ::1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host. 

或者当我尝试添加一个新的值,我得到:

 consul kv put foo bar Error! Failed writing data: Put http://127.0.0.1:8500/v1/kv/foo: dial tcp 127.0.0.1:8500: getsockopt: connection refused 

我错过了什么?

我刚刚尝试了你所发布的内容,似乎打开了8500端口

 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f4ac8a5233e2 consul "docker-entrypoint..." 2 minutes ago Up 2 minutes 8300-8302/tcp, 8301-8302/udp, 8600/tcp, 8600/udp, 0.0.0.0:8500->8500/tcp sharp_knuth 

我得到这个:

 Trying 0.0.0.0... Connected to dev-consul Escape character is '^]'. Connection closed by foreign host. 

但是,从日志中可以看到它正在运行:

 ==> Starting Consul agent... ==> Consul agent running! Version: 'v0.9.3' Node ID: '27998add-58f9-e424-84a0-038db228629f' Node name: '68bfdf141e7f' Datacenter: 'dc1' (Segment: '<all>') Server: true (Bootstrap: false) Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600) Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302) Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false ==> Log data will now stream in as it occurs: 2017/10/02 20:26:27 [DEBUG] Using random ID "27998add-58f9-e424-84a0-038db228629f" as node ID 2017/10/02 20:26:27 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:127.0.0.1:8300 Address:127.0.0.1:8300}] 2017/10/02 20:26:27 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "") 2017/10/02 20:26:27 [INFO] serf: EventMemberJoin: 68bfdf141e7f.dc1 127.0.0.1 2017/10/02 20:26:27 [INFO] serf: EventMemberJoin: 68bfdf141e7f 127.0.0.1 2017/10/02 20:26:27 [INFO] consul: Adding LAN server 68bfdf141e7f (Addr: tcp/127.0.0.1:8300) (DC: dc1) 2017/10/02 20:26:27 [INFO] consul: Handled member-join event for server "68bfdf141e7f.dc1" in area "wan" 2017/10/02 20:26:27 [INFO] agent: Started DNS server 0.0.0.0:8600 (udp) 2017/10/02 20:26:27 [INFO] agent: Started DNS server 0.0.0.0:8600 (tcp) 2017/10/02 20:26:27 [INFO] agent: Started HTTP server on [::]:8500 2017/10/02 20:26:27 [WARN] raft: Heartbeat timeout from "" reached, starting election 2017/10/02 20:26:27 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2 2017/10/02 20:26:27 [DEBUG] raft: Votes needed: 1 2017/10/02 20:26:27 [DEBUG] raft: Vote granted from 127.0.0.1:8300 in term 2. Tally: 1 2017/10/02 20:26:27 [INFO] raft: Election won. Tally: 1 2017/10/02 20:26:27 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state 2017/10/02 20:26:27 [INFO] consul: cluster leadership acquired 2017/10/02 20:26:27 [DEBUG] consul: Skipping self join check for "68bfdf141e7f" since the cluster is too small 2017/10/02 20:26:27 [INFO] consul: member '68bfdf141e7f' joined, marking health alive 2017/10/02 20:26:27 [INFO] consul: New leader elected: 68bfdf141e7f 2017/10/02 20:26:28 [INFO] agent: Synced node info 2017/10/02 20:27:27 [DEBUG] consul: Skipping self join check for "68bfdf141e7f" since the cluster is too small 2017/10/02 20:27:34 [DEBUG] agent: Node info in sync