Docker Kong admin API无法访问

时间:2018-07-17 13:59:42

标签: docker kong

我已将the Docker Kong image升级到0.14.0版本,它停止响应来自容器外部的连接:

$ curl 127.0.0.1:8001 --trace-ascii dump.txt

== Info: Rebuilt URL to: 127.0.0.1:8001/
== Info:   Trying 127.0.0.1...
== Info: Connected to 127.0.0.1 (127.0.0.1) port 8001 (#0)
=> Send header, 78 bytes (0x4e)
0000: GET / HTTP/1.1
0010: Host: 127.0.0.1:8001
0026: User-Agent: curl/7.47.0
003f: Accept: */*
004c: 
== Info: Recv failure: Connection reset by peer
== Info: Closing connection 0

端口映射为

  

0.0.0.0:8000-8001-> 8000-8001 / tcp,0.0.0.0:8443-8444-> 8443-8444 / tcp

尝试从容器内部进行连接时一切正常:

/ # curl 127.0.0.1:8001
{"plugins":{"enabled_in_cluster":[], ...

端口8000可从容器的外部和内部使用。那会是什么?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。原因是kong admin配置默认设置为回送地址。但是我没有修改配置文件。由于Kong Docker Image提供了一个环境变量来公开管理端口。

KONG_ADMIN_LISTEN="0.0.0.0:8001, 0.0.0.0:8444 ssl"

这会将管理端口绑定到主机端口

答案 1 :(得分:1)

问题出在/usr/local/kong/nginx-kong.conf中将管理服务器绑定到localhost

server {
    server_name kong_admin;
    listen 127.0.0.1:8001;
    listen 127.0.0.1:8444 ssl;
...

我已将以下代码添加到我的自定义入口点中,该入口点恰好在启动nginx之前删除了此绑定:

echo "Remove the admin API localhost binding..."
sed -i "s|^\s*listen 127.0.0.1:8001;|listen 0.0.0.0:8001;|g" /usr/local/kong/nginx-kong.conf && \
sed -i "s|^\s*listen 127.0.0.1:8444 ssl;|listen 0.0.0.0:8444 ssl;|g" /usr/local/kong/nginx-kong.conf

echo "Starting nginx $PREFIX..."

exec /usr/local/openresty/nginx/sbin/nginx \
  -p $PREFIX \
  -c nginx.conf

当然,必须在生产中以其他方式关闭管理端口。

相关问题