0

为了测试,我尝试在 docker 中运行 gcloud devserver 并附上该评论:

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 &

要检查 devserver 是否已成功启动,我使用以下脚本:

#!/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

运行所有测试后,我刚刚回来:

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

我无法确定启动 devserver 或查询端口是否有任何问题。有没有人有想法或解决方案?谢谢!

4

1 回答 1

0

默认情况下,仅接受 localhost|loopback 流量,您无法远程访问服务器。

请尝试将--address=0.0.0.0: (链接) 添加到您的java_dev_appserver.sh命令中。

例子

使用了 Google 的HelloWorld示例的变体。

运行它mvn appengine:run(以确认它有效并构建 WAR)。

然后/path/to/bin/java_dev_appserver.sh ./target/hellofreddie-0.1(确认它与本地开发服务器一起工作)。

然后使用 Google 的 Cloud SDK 容器镜像(链接),将之前生成的 WAR 目录挂载到其中,并在以下位置运行服务器: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

能够卷曲端点:

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

返回200

并且,运行您的脚本并根据PORT=9999返回值进行调整:

Port is open after 2 seconds.
于 2019-11-05T20:33:31.350 回答