Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kong don't work on Docker Cloud #1836

Closed
gfamorimo opened this issue Nov 20, 2016 · 6 comments
Closed

Kong don't work on Docker Cloud #1836

gfamorimo opened this issue Nov 20, 2016 · 6 comments

Comments

@gfamorimo
Copy link

Hi guys, I've spended all day trying make Kong work on Docker Cloud, but without success.
I've tried with cassandra and postgresql, without success for both.
I've tried with stack(similar docker-compose) and with one container for each part(Kong and Cassandra).
For both, I received the error bellow.

Steps To Reproduce

1.Stack
screen shot 2016-11-20 at 00 03 19

Additional Details & Logs

  • Log from Cassandra container

[kong-database-1]2016-11-20T02:08:04.334023633Z Unknown listen_address '172.17.0.11 10.7.0.12'
[kong-database-1]2016-11-20T02:08:04.334489365Z ERROR 02:08:04 Exception encountered during startup: Unknown listen_address '172.17.0.11 10.7.0.12'

  • Kong error logs
    [kong-1]2016-11-20T02:08:56.579175542Z Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:18: [cassandra error] All hosts tried for query failed. 127.0.0.1: connection refused for socket with peer 127.0.0.1.

So, someone had success trying put Kong on Docker-Cloud?

@shashiranjan84
Copy link
Contributor

shashiranjan84 commented Nov 20, 2016

What I see that you setting wrong Environment, You would need to prefix KONG_ to the CASSANDRA_CONTACT_POINTS environment variable.

https://getkong.org/docs/0.9.x/configuration/

@gfamorimo
Copy link
Author

I've made the ajust and the error remained.

screen shot 2016-11-20 at 12 44 30

@neilsmind
Copy link

So the issue appears to be with Cassandra 2.2 and hostname --ip-address returning more than one address - docker-library/cassandra#56

It also appears to be resolved in Docker itself here: moby/moby#26659

The only issue appears to be getting the Docker Host (node) updated. 😞

There is a suggestion in docker-library/cassandra#56 that setting an environment variable pointing to the name of the container would solve things but haven't gotten it to work yet:
CASSANDRA_LISTEN_ADDRESS=some-cassandra

@neilsmind
Copy link

neilsmind commented Dec 7, 2016

@gfamorimo - Got it working! Here's my stack config below.

Note that the links aren't necessary because we can just refer by hostname. Every container can contact every other container in a stack by hostname regardless of links...links brings over a whole message of environment variables that I'm not sure we need for this connection.

The important part is:

kong-database:
  environment:
    - CASSANDRA_LISTEN_ADDRESS=kong-database

Here's the full config...

kong:
  environment:
    - KONG_CASSANDRA_CONTACT_POINTS=kong-database
    - KONG_DATABASE=cassandra
  expose:
    - '7946'
    - '8000'
    - '8443'
  image: 'kong:latest'
  ports:
    - '8001:8001'
  restart: always
kong-database:
  environment:
    - CASSANDRA_LISTEN_ADDRESS=kong-database
  expose:
    - '9042'
    - '9160'
  image: 'cassandra:2.2'
  restart: always

@catscarlet
Copy link

You shouldn't startup like this in compose.
Cassandra starts very slow. It takes more than 18 seconds to start and listen the port 9042.
Starting by default, kong will start and try to connect 9042 while cassandra are not prepared.

You need a wait-for-it.sh for kong to wait for cassandra.

#!/usr/bin/env bash
#   Use this script to test if a given TCP host/port are available

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
    cat << USAGE >&2
Usage:
    $cmdname host:port [-s] [-t timeout] [-- command args]
    -h HOST | --host=HOST       Host or IP under test
    -p PORT | --port=PORT       TCP port under test
                                Alternatively, you specify the host and port as host:port
    -s | --strict               Only execute subcommand if the test succeeds
    -q | --quiet                Don't output any status messages
    -t TIMEOUT | --timeout=TIMEOUT
                                Timeout in seconds, zero for no timeout
    -- COMMAND ARGS             Execute command with args after the test finishes
USAGE
    exit 1
}

wait_for()
{
    if [[ $TIMEOUT -gt 0 ]]; then
        echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
    else
        echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
    fi
    start_ts=$(date +%s)
    while :
    do
        (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
        result=$?
        if [[ $result -eq 0 ]]; then
            end_ts=$(date +%s)
            echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
            break
        fi
        sleep 1
    done
    return $result
}
wait_for_wrapper()
{
    # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
    if [[ $QUIET -eq 1 ]]; then
        timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
    else
        timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
    fi
    PID=$!
    trap "kill -INT -$PID" INT
    wait $PID
    RESULT=$?
    if [[ $RESULT -ne 0 ]]; then
        echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
    fi
    return $RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
    case "$1" in
        *:* )
        hostport=(${1//:/ })
        HOST=${hostport[0]}
        PORT=${hostport[1]}
        shift 1
        ;;
        --child)
        CHILD=1
        shift 1
        ;;
        -q | --quiet)
        QUIET=1
        shift 1
        ;;
        -s | --strict)
        STRICT=1
        shift 1
        ;;
        -h)
        HOST="$2"
        if [[ $HOST == "" ]]; then break; fi
        shift 2
        ;;
        --host=*)
        HOST="${1#*=}"
        shift 1
        ;;
        -p)
        PORT="$2"
        if [[ $PORT == "" ]]; then break; fi
        shift 2
        ;;
        --port=*)
        PORT="${1#*=}"
        shift 1
        ;;
        -t)
        TIMEOUT="$2"
        if [[ $TIMEOUT == "" ]]; then break; fi
        shift 2
        ;;
        --timeout=*)
        TIMEOUT="${1#*=}"
        shift 1
        ;;
        --)
        shift
        CLI="$@"
        break
        ;;
        --help)
        usage
        ;;
        *)
        echoerr "Unknown argument: $1"
        usage
        ;;
    esac
done
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
    echoerr "Error: you need to provide a host and port to test."
    usage
fi
TIMEOUT=${TIMEOUT:-25}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
if [[ $CHILD -gt 0 ]]; then
    wait_for
    RESULT=$?
    exit $RESULT
else
    if [[ $TIMEOUT -gt 0 ]]; then
        wait_for_wrapper
        RESULT=$?
    else
        wait_for
        RESULT=$?
    fi
fi
if [[ $CLI != "" ]]; then
    if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
        echoerr "$cmdname: strict mode, refusing to execute subprocess"
        exit $RESULT
    fi
    exec $CLI
else
    exit $RESULT
fi

And my Dockerfile for kong

FROM kong:0.9.5

MAINTAINER catscarlet.com

ENV KONG_VERSION 0.9.5

COPY wait-for-it.sh /

CMD ["kong", "start"]

And my compose file for kong(I build the Docker image and stored it to my private docker registry)

version: '2'
services:
    kong-modified:
        image: my-registry:5000/catscarlet/kong-modified
        depends_on:
            - kong-database
        expose:
            - "8000"
            - "8001"
            - "7946"
        volumes:
            - /root/ssl/certificate:/usr/local/kong/ssl
        links:
            - kong-database
        environment:
            - KONG_DATABASE=cassandra
            - KONG_CASSANDRA_CONTACT_POINTS=kong-database
            - KONG_PG_HOST=kong-database
        ports:
            - "80:8000"
            - "8001:8001"
            - "7946:7946"
        command: ["/wait-for-it.sh", "kong-database:9042", "--", "kong", "start"]
    kong-database:
        image: cassandra:2.2
        expose:
            - "9042"

@p0pr0ck5
Copy link
Contributor

p0pr0ck5 commented May 5, 2017

Closing this, as it looks like there's no actionable work to take, and a solution has been posted.

@p0pr0ck5 p0pr0ck5 closed this as completed May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants