无法访问gcloud appengine devserver的端口



为了进行测试,我尝试在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或查询端口是否有任何问题。有人有想法或解决方案吗?谢谢

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

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

示例

使用了谷歌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.

最新更新