1

我尝试将 docker映像Eclipse theia送到 cf,但是无法启动它(或者更确切地说连接到它)。该图像使用 .公开端口 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 镜像中暴露的端口?当前图像中的端口不应该优先吗?

4

1 回答 1

2

更改路由映射有所帮助。以下步骤有所帮助:获取应用程序指南

~ % cf app theia-docker  --guid
8032eea6-d146-4d27-9b17-c7331852b59b

添加需要的端口

cf curl /v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b -X PUT -d '{"ports": [3000]}'
{
   "metadata": {
      "guid": "8032eea6-d146-4d27-9b17-c7331852b59b",
      "url": "/v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b",
      "created_at": "2021-06-12T09:04:51Z",
      "updated_at": "2021-06-12T17:58:03Z"
   },
   "entity": {
      "name": "theia-docker",
      "production": false,
.
.
.
"ports": [
         3000,
         2375,
         2376
      ],
.
.
.

获取附加到应用程序的路线

~ % cf curl /v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b/routes
{
   "total_results": 1,
   "total_pages": 1,
   "prev_url": null,
   "next_url": null,
   "resources": [
      {
         "metadata": {
            "guid": "21f89763-baab-456d-8151-aad383a3c28f",
.
.
.

使用 route-guid 查找 route_mappings:

cf curl /v2/routes/21f89763-baab-456d-8151-aad383a3c28f/route_mappings
{
   "total_results": 1,
   "total_pages": 1,
   "prev_url": null,
   "next_url": null,
   "resources": [
      {
         "metadata": {
            "guid": "33bde252-ad3e-49b4-91df-78543ac452b4",
            "url": "/v2/route_mappings/33bde252-ad3e-49b4-91df-78543ac452b4",
            "created_at": "2021-06-12T09:04:51Z",
            "updated_at": "2021-06-12T09:04:51Z"
         },
         "entity": {
            "app_port": null,
            "app_guid": "8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_guid": "21f89763-baab-456d-8151-aad383a3c28f",
            "app_url": "/v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_url": "/v2/routes/21f89763-baab-456d-8151-aad383a3c28f"
         }
      }
   ]
}

使用 app_guid、route_guid 和 app_port 更新路由映射:

~% cf curl /v2/route_mappings -X POST -d '{"app_guid":"8032eea6-d146-4d27-9b17-c7331852b59b","route_guid":"21f89763-baab-456d-8151-aad383a3c28f", "app_port":3000}'
{
   "metadata": {
      "guid": "a62a2ea6-859f-48cc-aa33-a8d6583081da",
      "url": "/v2/route_mappings/a62a2ea6-859f-48cc-aa33-a8d6583081da",
      "created_at": "2021-06-12T18:02:19Z",
      "updated_at": "2021-06-12T18:02:19Z"
   },
   "entity": {
      "app_port": 3000,
      "app_guid": "8032eea6-d146-4d27-9b17-c7331852b59b",
      "route_guid": "21f89763-baab-456d-8151-aad383a3c28f",
      "app_url": "/v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b",
      "route_url": "/v2/routes/21f89763-baab-456d-8151-aad383a3c28f"
   }
}

再次列出路由映射:

~ % cf curl /v2/routes/21f89763-baab-456d-8151-aad383a3c28f/route_mappings
{
   "total_results": 2,
   "total_pages": 1,
   "prev_url": null,
   "next_url": null,
   "resources": [
      {
         "metadata": {
            "guid": "33bde252-ad3e-49b4-91df-78543ac452b4",
            "url": "/v2/route_mappings/33bde252-ad3e-49b4-91df-78543ac452b4",
            "created_at": "2021-06-12T09:04:51Z",
            "updated_at": "2021-06-12T09:04:51Z"
         },
         "entity": {
            "app_port": null,
            "app_guid": "8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_guid": "21f89763-baab-456d-8151-aad383a3c28f",
            "app_url": "/v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_url": "/v2/routes/21f89763-baab-456d-8151-aad383a3c28f"
         }
      },
      {
         "metadata": {
            "guid": "a62a2ea6-859f-48cc-aa33-a8d6583081da",
            "url": "/v2/route_mappings/a62a2ea6-859f-48cc-aa33-a8d6583081da",
            "created_at": "2021-06-12T18:02:19Z",
            "updated_at": "2021-06-12T18:02:19Z"
         },
         "entity": {
            "app_port": 3000,
            "app_guid": "8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_guid": "21f89763-baab-456d-8151-aad383a3c28f",
            "app_url": "/v2/apps/8032eea6-d146-4d27-9b17-c7331852b59b",
            "route_url": "/v2/routes/21f89763-baab-456d-8151-aad383a3c28f"
         }
      }
   ]
}

您将找到已创建的新路由映射。删除不需要的。

~ % cf curl /v2/route_mappings/33bde252-ad3e-49b4-91df-78543ac452b4 -X DELETE

就是这样。欢迎任何更好的解决方案:)。(当然不涉及维护基础镜像的Dockerfile)

于 2021-06-12T18:22:24.223 回答