haproxy / docker未启用侦听程序(检查“绑定”指令)! 退出

我试图与docker运行haproxy。 我遵循这里的指示:

https://hub.docker.com/_/haproxy/

我能够build立docker图像,但尝试运行后。

运用

docker run -d --link another_container:another_container --name mc-ha -v haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro my_own_haproxy:latest 

我得到这个错误:

 [ALERT] 298/054910 (1) : [haproxy.main()] No enabled listener found (check for 'bind' directives) ! Exiting. 

我search了它,但我发现的唯一的东西是ha代理的源代码。

这是我的haproxy.cfg

 global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # Default ciphers to use on SSL-enabled listening sockets. # For more information, see ciphers(1SSL). ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend esNodes bind *:8091 mode http default_backend srNodes backend srNodes mode http balance roundrobin option forwardfor http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } option httpchk HEAD / HTTP/1.1\r\nHost:localhost server web01 0.0.0.0:10903/project/es check 

编辑:顺便说一句我也试着改变后台节点的url到我的docker主机IP。 但是还是没有运气。

你会想从你的docker文件中删除daemon关键字 – docker需要一个前台进程才能运行,否则docker会立即退出。

我认为你看到的错误信息是因为docker退出比haproxy绑定到任何端口更快。

感谢@迈克尔评论。 我能解决这个问题。

首先,我从dockerfile中删除haproxy命令。 然后我在容器中手动运行haproxy命令。

瞧! 我的configuration文件不是一个文件。 它的一个目录。 大声笑

问题是在我的docker命令-v。

我将其改为完整path

-v FULL_PATH / customhaproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg

我实际上不得不重新启动docker-machine (使用OSX),否则我每次运行带有卷装入选项的container时(尝试了绝对path和相对path) – 将haproxy.cfg为一个目录

 ls -l /etc/ssl/certs ls -l /etc/ssl/private chmod -r 400 /etc/ssl/private 

也许也改变了证书的权限,但我不知道。 用全局可读的ssl密钥启动haproxy是一个非常糟糕的安全实践,所以它们完全禁用了启动。