Spring Docker 中的启动应用收到:错误 R10(启动超时)-> Web 进程无法在启动后 60 秒内绑定到 $PORT
Spring Boot app in Docker receives: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
我在 Docker 中有一个在 Heroku 上运行的 Spring 引导应用程序。
最近,将 Tomcat 更新到 10.1.0-M10 后,我开始收到此错误:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within
60 seconds of launch
由于早期版本中的漏洞,立即降级到较低版本的想法行不通。我检查了可能的原因并发现 Tomcat binding port issue.
我无法为不同的端口设置固定配置,因为我正在部署到 Heroku 并依赖于它们的随机端口。
我的Docker文件:
FROM azul/zulu-openjdk-alpine:11
ENV PORT=$PORT
COPY /target/app.jar /app.jar
CMD java -Xms256m -Xmx512m \
-Dlog4j2.formatMsgNoLookups=true \
-Djava.security.egd=file:/dev/./urandom \
-Dserver.port=$PORT \
-jar /app.jar
有什么办法解决?有什么我遗漏的吗?
更新:
还有更多来自 Heroku 的日志:
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.057 [main] INFO c.g.s.z.ApplicationKt - Started ApplicationKt in 8.09 seconds (JVM running for 9.062)
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.060 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state LivenessState changed to CORRECT
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.063 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
Feb 22 12:51:06 integration-test heroku/web.1 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
我找到了一个不完美但似乎对我有用的解决方案。
- 降级 Spring 从
2.6.3
启动到 2.6.1
- 已将 Tomcat 从
10.X.X
降级为 9.X.X
- 删除了开发工具依赖项
我认为最近的两个很神奇。开发工具停止在 test/prod 环境中请求额外的端口。 Tomcat 在版本 9.X.X
中绑定端口,但在 10.X.X
.
中未绑定
尽管我找到了解决方案,但我不知道为什么会这样,而且它并不完美security-wise。
从错误消息来看,似乎 $PORT
没有解析到任何环境变量。
部署到 heroku 你必须使用 .env
文件来定义环境变量(你不能使用 docker run -e PORT=1234
)see documentation
When you use heroku locally, you can set config vars in a .env file. When heroku local is run .env is read and each name/value pair is set in the environment. You can use this same .env file when using Docker: docker run -p 5000:5000 --env-file .env <image-name>
我在 Docker 中有一个在 Heroku 上运行的 Spring 引导应用程序。
最近,将 Tomcat 更新到 10.1.0-M10 后,我开始收到此错误:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
由于早期版本中的漏洞,立即降级到较低版本的想法行不通。我检查了可能的原因并发现 Tomcat binding port issue.
我无法为不同的端口设置固定配置,因为我正在部署到 Heroku 并依赖于它们的随机端口。
我的Docker文件:
FROM azul/zulu-openjdk-alpine:11
ENV PORT=$PORT
COPY /target/app.jar /app.jar
CMD java -Xms256m -Xmx512m \
-Dlog4j2.formatMsgNoLookups=true \
-Djava.security.egd=file:/dev/./urandom \
-Dserver.port=$PORT \
-jar /app.jar
有什么办法解决?有什么我遗漏的吗?
更新:
还有更多来自 Heroku 的日志:
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.057 [main] INFO c.g.s.z.ApplicationKt - Started ApplicationKt in 8.09 seconds (JVM running for 9.062)
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.060 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state LivenessState changed to CORRECT
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.063 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
Feb 22 12:51:06 integration-test heroku/web.1 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
我找到了一个不完美但似乎对我有用的解决方案。
- 降级 Spring 从
2.6.3
启动到2.6.1
- 已将 Tomcat 从
10.X.X
降级为9.X.X
- 删除了开发工具依赖项
我认为最近的两个很神奇。开发工具停止在 test/prod 环境中请求额外的端口。 Tomcat 在版本 9.X.X
中绑定端口,但在 10.X.X
.
尽管我找到了解决方案,但我不知道为什么会这样,而且它并不完美security-wise。
从错误消息来看,似乎 $PORT
没有解析到任何环境变量。
部署到 heroku 你必须使用 .env
文件来定义环境变量(你不能使用 docker run -e PORT=1234
)see documentation
When you use heroku locally, you can set config vars in a .env file. When heroku local is run .env is read and each name/value pair is set in the environment. You can use this same .env file when using Docker:
docker run -p 5000:5000 --env-file .env <image-name>