Cannot reach port of gcloud appengine devserver

184 Views Asked by At

for testing I try to run the gcloud devserver inside docker with that comment:

sudo /usr/local/gcloud/google-cloud-sdk/bin/java_dev_appserver.sh --disable_update_check --port=8888 --help /app/target/qdacity-war/ 2>&1 | sudo tee /app/logs/devserver.log > /dev/null &

To check if the devserver has started successfully, I use this script:

#!/bin/bash
# This script waits until the port 8888 is open.

SERVER=localhost
PORT=8888

TIMEOUT=180
TIME_INTERVAL=2

PORT_OPEN=1
PORT_CLOSED=0

time=0
isPortOpen=0

while [ $time -lt $TIMEOUT ] && [ $isPortOpen -eq $PORT_CLOSED ];
do 

    # Connect to the port
    (echo > /dev/tcp/$SERVER/$PORT) >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        isPortOpen=$PORT_CLOSED
    else
        isPortOpen=$PORT_OPEN
    fi

    time=$(($time+$TIME_INTERVAL))
    sleep $TIME_INTERVAL
done

if [ $isPortOpen -eq $PORT_OPEN ]; then
    echo "Port is open after ${time} seconds."

    # Give the server more time to properly start
    sleep 10
else
    echo "Reached the timeout (${TIMEOUT} seconds). The port ${SERVER}:${PORT} is not available."

    exit 1
fi

After running all the test, I just got back:

Reached the timeout (180 seconds). The port localhost:8888 is not available.

I couldn't find out if there were any problems starting the devserver or querying the port. Does anyone have an idea or solution? Thanks!

1

There are 1 best solutions below

1
On

By default, by only accepting localhost|loopback traffic, you're unable to access the server remotely.

Please try adding --address=0.0.0.0: (link) to your java_dev_appserver.sh command.

Example

Used a variant of Google's HelloWorld sample.

Ran this with mvn appengine:run (to confirm it works and build the WAR).

Then /path/to/bin/java_dev_appserver.sh ./target/hellofreddie-0.1 (to confirm it works with the local development server).

Then used Google's Cloud SDK container image (link), mounted the previously generated WAR directory into it, and ran the server on :9999:

docker run \
--interactive \
--tty \
--publish=9999:9999 \
--volume=${PWD}/target:/target \
google/cloud-sdk \
  /usr/lib/google-cloud-sdk/bin/java_dev_appserver.sh \
  --address=0.0.0.0 \
  --port=9999 \
  ./target/hellofreddie-0.1

Am able to curl the endpoint:

curl \
--silent \
--location \
--write-out "%{http_code}" \
--output /dev/null \
localhost:9999

returns 200

And, running your scripts adjusted with PORT=9999 returns:

Port is open after 2 seconds.