簡體   English   中英

錯誤 R10(啟動超時)> Web 進程未能在啟動后 90 秒內綁定到 $PORT

[英]Error R10 (Boot timeout) > Web process failed to bind to $PORT within 90 seconds of launch

我正在部署一個帶有 CMD 行的 Docker 映像:

CMD ["java","-XX:+UnlockExperimentalVMOptions","-XX:+UseCGroupMemoryLimitForHeap","-Djava.security.egd=file:/dev/./urandom","-Dspring.server.port=$PORT","-Dserver.port=$PORT","-jar","/life-project.jar"]

在日志中它看起來像:

2018-08-06T10:51:17.489612+00:00 heroku[web.1]: Starting process with command java -XX:\+UnlockExperimentalVMOptions -XX:\+UseCGroupMemoryLimitForHeap -Djava.security.egd\=file:/dev/./urandom -Dspring.server.port\=\48227 -Dserver.port\=\48227 -jar /life-project.jar

出現以下錯誤:

2018-08-06T10:51:26.106011+00:00 app[web.1]: ***************************
2018-08-06T10:51:26.106012+00:00 app[web.1]: APPLICATION FAILED TO START
2018-08-06T10:51:26.106014+00:00 app[web.1]: ***************************
2018-08-06T10:51:26.106015+00:00 app[web.1]:
2018-08-06T10:51:26.106017+00:00 app[web.1]: Description:
2018-08-06T10:51:26.106018+00:00 app[web.1]:
2018-08-06T10:51:26.106020+00:00 app[web.1]: Failed to bind properties under 'server.port' to java.lang.Integer:
2018-08-06T10:51:26.106021+00:00 app[web.1]:
2018-08-06T10:51:26.106022+00:00 app[web.1]: Property: server.port
2018-08-06T10:51:26.106024+00:00 app[web.1]: Value: $PORT
2018-08-06T10:51:26.106025+00:00 app[web.1]: Origin: "server.port" from property source "systemProperties"
2018-08-06T10:51:26.106026+00:00 app[web.1]: Reason: failed to convert java.lang.String to java.lang.Integer
2018-08-06T10:51:26.106028+00:00 app[web.1]:
2018-08-06T10:51:26.106029+00:00 app[web.1]: Action:
2018-08-06T10:51:26.106030+00:00 app[web.1]:
2018-08-06T10:51:26.106032+00:00 app[web.1]: Update your application's configuration

我應該在配置中更改什么?

您需要在application.properties (或 yaml)中創建以下條目:

server.port=${PORT:8080}

原因在Docker 文檔中有所描述。 您可以將$ vars 放在CMD

-Dserver.port應該是第一個,像這樣

CMD [ "sh", "-c", "java -Dserver.port=$PORT -Xmx300m -Xss512k -Dfile.encoding=UTF-8 -Dspring.profiles.active=prod -Djava.security.egd=file:/dev/./urandom -jar /opt/application.jar" ]

在此處輸入圖片說明

其他答案一般來說是正確的,但取決於環境,(1) 可能未定義PORT ,以及 (2) var PORT可能會在主機 > 容器 > JVM 之間的轉換中丟失。 如果您使用-Dserver.port而不是--server.port則尤其如此。

對我來說,解決這個問題的是默認 application.properties 和 Dockerfile 中的值,並使用--server.port而不是-Dserver.port

// application.properties
server.port=${PORT:8080}
// Dockerfile
CMD ["java", "-jar", "myapp.jar", "--server.port=${PORT:8080}"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM