Azure Linux Web 服务器没有响应我的 Docker 容器

编程入门 行业动态 更新时间:2024-10-08 14:50:58

Azure Linux Web 服务器没有响应我的 Docker <a href=https://www.elefans.com/category/jswz/34/1771431.html style=容器"/>

Azure Linux Web 服务器没有响应我的 Docker 容器

我正在尝试通过 Azure 容器注册表将我的小型节点 js 应用程序部署到 azure web 服务。

这是我的 server.js

const express = require('express');
const path = require('path');

const app = express();

// Serve the static files from the build directory
app.use(express.static(path.join(__dirname, 'build')));

// Serve the React app on all other routes
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

// Start the server
const port = 3000;
app.listen(port, () => {
    console.log('BEGIN');
    console.log(`Server started on port ${port}`);
});

这是我的 Dockerfile

# Use the official Node.js 16.x image as the base image
FROM node:16-alpine

WORKDIR /app

RUN npm install express

COPY "./server.js" .
COPY "./packages/claim-management/build" "./build"

EXPOSE 3000
CMD ["node", "server.js"]

我在端口暴露的配置中添加了两个变量。

  WEBSITES_CONTAINER_START_TIME_LIMIT   = 400
  WEBSITES_PORT                         = 3000

这是我来自 Azure 的日志:

2023-03-25T12:04:11.620Z INFO  - Initiating warmup request to container claim-management_0_cd4e268d_msiProxy for site claim-management
2023-03-25T12:04:11.633Z INFO  - Container claim-management_0_cd4e268d_msiProxy for site claim-management initialized successfully and is ready to serve requests.
2023-03-25T12:04:11.634Z INFO  - Initiating warmup request to container claim-management_0_cd4e268d for site claim-management
2023-03-25T12:04:11.382860821Z exec /usr/local/bin/docker-entrypoint.sh: exec format error
2023-03-25T12:04:26.892Z ERROR - Container claim-management_0_cd4e268d for site claim-management has exited, failing site start
2023-03-25T12:04:26.900Z ERROR - Container claim-management_0_cd4e268d didn't respond to HTTP pings on port: 3000, failing site start. See container logs for debugging.
2023-03-25T12:04:26.906Z INFO  - Stopping site claim-management because it failed during startup.

容器在本地工作,我可以通过命令

docker run -p 3000:3000
运行它,但我可以看到 Azure 试图通过 `docker run -d --expose=3000 启动容器。我不知道我做错了什么。

回答如下:

我修好了: 只要确保(如果您是 mac m1 用户或任何其他与 Azure Web 服务不兼容的处理器)您将平台添加到您的 Dockerfile:

# Need platform to much with your current extension
FROM --platform=linux/amd64 node:16-alpine

WORKDIR /app

COPY "./server.js" .

EXPOSE 3000

CMD ["node", "server.js"]

确保在应用服务的配置部分使用 WEBSITES_PORT 变量,并且它与 Dockerfile 中的 EXPOSE 端口相匹配!

更多推荐

Azure Linux Web 服务器没有响应我的 Docker 容器

本文发布于:2024-05-13 16:48:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   服务器   Linux   Azure   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!