容器"/>
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 容器
发布评论