Azure Linux Web Server无法响应Docker容器问题求助
问题排查:Azure Web Apps容器启动失败(exec format error)
相关代码与配置
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.
关键问题分析与解决
日志中的exec /usr/local/bin/docker-entrypoint.sh: exec format error是核心故障点,根源是容器镜像架构与Azure Web Apps宿主环境不兼容:
- 若本地是Apple Silicon(ARM架构)设备,Docker默认构建ARM64镜像,但Azure Web Apps使用x86_64架构
- 本地能正常运行是因为Docker自动做了架构适配,而Azure无法跨架构执行镜像
解决方案步骤
构建x86_64架构镜像
在本地执行构建命令时指定目标平台:docker build --platform linux/amd64 -t <你的ACR名称>/claim-management:v1 .推送镜像至Azure容器注册表
docker push <你的ACR名称>/claim-management:v1重新部署并重启实例
确保Azure Web Apps拉取新推送的x86_64镜像,然后重启Web Apps实例。
验证方法
- 本地用
docker run --platform linux/amd64 -p 3000:3000 <镜像名>测试x86镜像的运行状态 - 部署后查看Azure日志,确认不再出现
exec format error,容器正常启动
内容的提问来源于stack exchange,提问作者Sebastian Lagua
相关产品推荐
相关产品推荐

