【发布时间】:2015-08-21 12:43:49
【问题描述】:
我在 EC2 中运行 coreOS。 我有一个 nodeJS api docker 映像并在几个端口(25001 和 25002)中运行它。当我向他们蜷缩时,我看到了正确的反应。
我的意图是在这些之上有一个 HAProxy(运行在 25000),它将在这两者之间进行负载平衡。 所以这是我做的步骤:
HaProxy 的 DockerFile:
FROM haproxy:1.5
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
haproxy.cfg:
global
# daemon
maxconn 256
log /dev/log local0
defaults
mode http
log global
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:25000
default_backend node_api
backend node_api
mode http
balance roundrobin
server api1 localhost:25001
server api2 localhost:25002
结果: 当我为单个服务运行 curl 时,它们会起作用 --->
curl -i localhost:25001/ping
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Content-Length: 68
ETag: W/"44-351401c7"
Date: Sat, 06 Jun 2015 17:22:09 GMT
Connection: keep-alive
{"error":0,"msg":"loc receiver is alive and ready for data capture"}
同样适用于 25002 但是当我运行 25000 时,我得到一个超时错误,如下所示:
curl -i localhost:25000/ping
HTTP/1.0 504 Gateway Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
我想知道我在这里做错了什么?任何帮助将不胜感激...
【问题讨论】:
-
你是如何启动你的 Docker 容器的?
-
Docker 运行 -d -p 25000:25000 镜像名称
-
那是给哈的。对于节点容器 - docker run -d -p 2501:2500 --name api1 image
标签: node.js docker haproxy docker-compose