【发布时间】:2021-06-12 17:08:01
【问题描述】:
我尝试将 docker image 或 Eclipse theia 推送到 cf,但无法启动它(或者更确切地说连接到它)。图像exposes 端口3000 与EXPOSE 3000。该应用程序在本地运行并运行它会打开默认的 theia 主屏幕
在 CF 上,提供了足够的磁盘和内存。
当设置了默认的port 健康检查时,cf 在启动应用时挂起。
Creating app theia-docker...
Mapping routes...
Staging app and tracing logs...
Cell 15fcfa4a-a364-4dc2-ab6b-349f5196bd80 creating container for instance bd4b9e65-946f-485a-9de1-5c7fc8d4ad01
Cell 15fcfa4a-a364-4dc2-ab6b-349f5196bd80 successfully created container for instance bd4b9e65-946f-485a-9de1-5c7fc8d4ad01
Staging...
Staging process started ...
Staging process finished
Exit status 0
Staging Complete
Cell 15fcfa4a-a364-4dc2-ab6b-349f5196bd80 stopping instance bd4b9e65-946f-485a-9de1-5c7fc8d4ad01
Cell 15fcfa4a-a364-4dc2-ab6b-349f5196bd80 destroying container for instance bd4b9e65-946f-485a-9de1-5c7fc8d4ad01
Cell 15fcfa4a-a364-4dc2-ab6b-349f5196bd80 successfully destroyed container for instance bd4b9e65-946f-485a-9de1-5c7fc8d4ad01
最终到FAILED
cf 日志会显示:
2021-06-12T14:37:25.40+0530 [APP/PROC/WEB/0] OUT root INFO Deploy plugins list took: 161.7 ms
2021-06-12T14:38:24.77+0530 [HEALTH/0] ERR Failed to make TCP connection to port 2375: connection refused; Failed to make TCP connection to port 2376: connection refused
2021-06-12T14:38:24.77+0530 [CELL/0] ERR Failed after 1m0.303s: readiness health check never passed.
为什么它使用了错误的端口号?
如果我尝试将 env 变量中的端口设置为cf set-env PORT 3000,我会得到
FAILED
Server error, status code: 400, error code: 100001, message: The app is invalid: environment_variables cannot set PORT
然后我将健康检查设置为process。当然,这将成功启动(失败与否)。检查日志可以看到应用程序已经成功启动。当我 ssh 进入应用程序 (cf ssh theia-docker) 时,我可以将应用程序卷曲为 localhost:3000 并返回主页的 HTML。
~ % cf ssh theia-docker
bash-5.0$ curl localhost:3000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="./bundle.js" charset="utf-8"></script>
</head>
<body>
<div class="theia-preload"></div>
</body>
</html>bash-5.0$
但是,当我尝试通过应用程序 URL 连接到应用程序时,出现错误:
502 Bad Gateway: Registered endpoint failed to handle the request.
我看到这个的原因是我用于此的基本映像是基于docker:dind 的,并且在基本映像中似乎暴露了 2375 和 2376 端口。
为什么 CF 选择基础镜像中公开的端口,而不是创建的 docker 镜像中公开的端口?当前镜像中的端口不应该优先吗?
【问题讨论】:
-
github.com/moby/moby/issues/3465 似乎是一个相关问题。
-
CF 默认会选择你的图片暴露的最小路由号。在您的回答中,您列出了三个端口 2375、2376 和 3000。默认情况下和这个逻辑,我希望它选择 2375。
标签: docker containers cloud-foundry gorouter