Mik*_*ike 9 https azure node.js express docker
我遇到了一个烦人的问题,我的容器化应用程序在本地运行良好,但在部署到 azure 时失败,尽管端口已正确公开。
没有 docker:
node app.js
通过https://localhost:443运行良好
使用 docker:
docker build -t myapp:latest .然后
docker run -p 49160:443 -d myapp:latest
通过https://localhost:49160运行良好
在这两种情况下,我都从我的 nodejs 应用程序中获得了预期的输出:
Running in production on x64
Express HTTPS server listening on port 443
mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
Run Code Online (Sandbox Code Playgroud)
(显然, myapp 和 mydb 不是实际名称。为了方便起见,此处使用。)
在配置 -> 应用程序设置下:
PORT=443
WEBSITES_PORT=443
DOCKER_ENABLE_CI=true
Run Code Online (Sandbox Code Playgroud)
管道设置myrepo/myapp:latest在构建时从私有 Docker Hub 存储库中拉取 docker 镜像。图像被正确拉出。
通过https://myapp.azurewebsites.net/失败,错误 503 Service Temporously Unavailable。
蔚蓝日志:
2020-04-10 18:02:21.040 INFO - Pulling image: myrepo/myapp:latest
2020-04-10 18:02:22.128 INFO - latest Pulling from myrepo/myapp
2020-04-10 18:02:22.129 INFO - Digest: sha256:982[...]
2020-04-10 18:02:22.129 INFO - Status: Image is up to date for myrepo/myapp:latest
2020-04-10 18:02:22.131 INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2020-04-10 18:02:22.143 INFO - Starting container for site
2020-04-10 18:02:22.144 INFO - docker run -d -p 7909:443 --name myapp_0_138f197c -e PORT=80 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=443 -e WEBSITE_SITE_NAME=myapp -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=myapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=6fc3[...] myrepo/myapp:latest
2020-04-10 18:02:22.144 INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-04-10 18:02:23.473 INFO - Initiating warmup request to container myapp_0_138f197c for site myapp
2020-04-10 18:02:45.304 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 21.8308149 sec
[...]
2020-04-10 18:06:08.252 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 224.7791547 sec
2020-04-10T18:02:24.893958779Z Running in production on x64
2020-04-10T18:02:26.275376640Z Express HTTPS server listening on port 80
2020-04-10T18:02:26.601261213Z mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
2020-04-10 18:06:14.346 ERROR - Container myapp_0_138f197c for site myapp did not start within expected time limit. Elapsed time = 230.8732099 sec
2020-04-10 18:06:14.365 ERROR - Container myapp_0_138f197c didn't respond to HTTP pings on port: 443, failing site start. See container logs for debugging.
2020-04-10 18:06:14.427 INFO - Stoping site myapp because it failed during startup.
Run Code Online (Sandbox Code Playgroud)
为什么容器化应用程序似乎可以正确启动,如 azure 日志中所见,但容器无法响应 443 上的 HTTP ping,这在 dockerfile 和 azure 中都暴露在 PORT 和 WEBSITES_PORT 中?
我是否需要让我的 HTTPS 服务器明确响应 HTTP PING,如果需要,我该怎么做?
Dockerfile:
FROM node:12
WORKDIR /usr/src/myapp
COPY package*.json ./
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
RUN npm install
COPY . .
EXPOSE 443
CMD [ "node", "app.js" ]
Run Code Online (Sandbox Code Playgroud)
这个问题可能被认为是重复的,但与下面的大多数问题相比,我提供了更多的相关信息。此外,我花了大量时间进行故障排除,但这些相关资源似乎都没有帮助:
在应用服务级别强制实施 HTTPS 时,将发生 TLS 终止并且流量将路由到您的容器端口,因此无需从您的容器强制实施 TLS。
如果您的容器侦听另一个端口(例如:8081),只需将WEBSITES_PORT应用程序设置设置为该端口号。应用服务将侦听端口 80 并将流量转发到您的容器端口。
| 归档时间: |
|
| 查看次数: |
4694 次 |
| 最近记录: |