Kong: docker-compose returning 502's from services

Created on 31 Mar 2016  路  5Comments  路  Source: Kong/kong

Hi there,

I originally posted this on docker-kong but haven't received a response.

I have the following set-up:

cassandra:
  image: cassandra:2.2.5

kong:
  image: mashape/kong
  links:
    - cassandra
  security_opt:
    - seccomp:unconfined
  ports:
    - "8000:8000"
    - "8443:8443"
    - "8001:8001"
    - "7946:7946"
    - "7946:7946/udp"

core-api:
  build: ./applications/core/api
  ports:
    - "8080:8080"
  links:
    - core-datastore 
    - core-cache
    - elasticsearch
  environment:
    - DB_NAME=bandzest
    - VIRTUAL_HOST=core.bandzest.dev
  restart: always

Then when I run curl -i -XGET http://bandzest.dev:8000 --header 'Host: core.bandzest.dev' -d 'request_path=api/v1/artists'

I get...

HTTP/1.1 502 Bad Gateway
Date: Thu, 31 Mar 2016 00:20:13 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/0.7.0

An invalid response was received from the upstream server
Whereas if I go straight to the API, I get a proper response.

I've read that Kong binds to 127.0.0.1 but docker-machine's something like 192.168.99.100, how do I change these? I changed the bind ip value in /etc/kong/kong.yml from 0.0.0.0 to my docker-machine ip, but that didn't make a difference.

Any pointers? Thanks in advance.

Most helpful comment

@EwanValentine Could you explain more about your solution? I got same error.

All 5 comments

@EwanValentine where you able to figure this out?

Yeah, it was something Docker related in the end!

@EwanValentine Could you explain more about your solution? I got same error.

@EwanValentine Did it have to do with correctly linking from Kong to your core-api container? That was my problem. I wasn't connecting to the correct port and it was throwing that 502.

@EwanValentine @JakeGlascock how did you get the kong container to connect to the correct port for your api container?

For example, the code from kong's docs shows something like the following for running the kong docker container:
docker run -d --name kong --link kong-database:kong-database -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp kong

So, assuming I have another docker container called "api" running on the same host, I should be able to something like the following:
docker run -d --name kong --link kong-database:kong-database --link api:api -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp kong

However, upon making requests to the kong proxy with something like the following:
curl -i -X GET --url http://localhost:8000/ --header 'Host: myhost.com',
I continue to see 502s with An invalid response was received from the upstream server.

Any help would be appreciated.

Was this page helpful?
0 / 5 - 0 ratings