用Kong揭露Konga

时间:2018-01-15 11:31:11

标签: dockerfile kong docker-stack

我正在使用Kong来公开Konga - 这是一个用于Kong管理界面的UI。

我正在使用docker stack和以下dockerfile运行它:

(gdb) bt 1
#0  Handler::send (this=0x2ba2b10, src=..., to=..., newMessage=true) at main.cpp:138

我使用命令

启动堆栈
version: "3.1"

secrets:
  webservices_hostname:
    external: true
  webservices_cert:
    external: true
  webservices_key:
    external: true

services:

#Create a new empty database for kong to use
# postgress used instead of cassendra as I haven't been able to find a healthcheck command for cassendra
  kong-database:
    image: postgres:9.4
    deploy:
      restart_policy:
        condition: any
    environment:
      - POSTGRES_USER=kong
      - POSTGRES_DB=kong
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

#Setup kong database
  kong-migration:
    image: kong
    deploy:
      restart_policy:
        condition: on-failure
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
    command: kong migrations up
    deploy:
      restart_policy:
        condition: on-failure

#Start the kong server
  kong:
    image: kong
    deploy:
      restart_policy:
        condition: any
    secrets:
     - webservices_cert
     - webservices_key
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_DATABASE=kong
      - KONG_SSL_CERT=/run/secrets/webservices_cert
      - KONG_SSL_CERT_KEY=/run/secrets/webservices_key
    ports:
      - 80:8000
      - 443:8443
    healthcheck:
      test: ["CMD-SHELL", "curl -I -s -L http://127.0.0.1:8000 || exit 1"]
      interval: 5s
      retries: 10
    restart: on-failure

#The next section starts a UI for kong called konga. 
#We only need a ui for development experimentation and can be removed if no UI is required
# when it is running it can be accessed on port 1337
  konga:
    image: pantsel/konga
    deploy:
      restart_policy:
        condition: on-failure
    ports:
     - 1337:1337

#Configure kong to forward requests to flaskapp
  kong-addapis-konga:
    image: byrnedo/alpine-curl
    deploy:
      restart_policy:
        condition: on-failure
    command: "-i -X POST \
                --url http://kong:8001/apis/ \
                --data 'name=flaskapp' \
                --data 'uris=/flaskapp' \
                --data 'upstream_url=http://flaskapp:80'
                --data 'https_only=false'
             "

如果我访问主持人:1337 Konga将正常工作。我可以去连接,它连接到kong admin api没有问题(http://kong:8001

但是,如果我访问https://host:443/kongahttp://host:80/konga,它会毫无问题地进入konga,但是当我尝试让konga连接到kong时,我收到错误:

“哦快攻!无法连接到http://kong:8001

为什么通过Kong访问Konga会导致这种行为?我认为如何连接到Konga并不重要 - 一旦到达那里,使用直接暴露的端口或通过Kong应该没有区别。

任何见解?

2 个答案:

答案 0 :(得分:1)

您应该创建一个网络并将其连接到kong。在konga配置中使用创建的网络。

docker network create my-net

docker network connect my-net kong

docker run --rm --network my-net -p 8080:8080 pantsel/konga start --kong-url http://kong:8001

答案 1 :(得分:0)

我也遇到了同样的错误,在路线的末尾添加了一个斜杠解决了该问题。 而不是http://host:80/konga致电http://host:80/konga/ 因此,该路线将代替/ konga,/ konda /