容器 Startup 失败
错误信息
错误响应从 daemon: 容器失败到 开始
快速摘要
容器 exits immediately or 失败到 开始, 经常 due 到 missing entrypoint, 错误 command, or application crash on boot.
为什么发生
Missing or 不正确 ENTRYPOINT/CMD in Dockerfile
Application crashes on startup due 到 missing 配置 or dependencies
entrypoint script 有语法错误 or 引用 missing file
容器's 用户 lacks permission 到执行 entrypoint
最小示例
FROM node:18
COPY . .
CMD ["npm", "run", "prod"] # script "prod" does not existFROM node:18
COPY . .
CMD ["npm", "start"] # correct script namebroken code 引用非-existent npm script. fix uses 正确 script name 定义 in 包.JSON.
如何诊断
检查容器 logs 使用
docker logs <容器>orkubectl logs <pod>运行镜像 interactively 到测试:
docker 运行 -它 --entrypoint /bin/sh <镜像>验证 ENTRYPOINT and CMD in Dockerfile 是正确
检查如果 application 开始 successfully on 你的局部 machine
如何修复
Fix ENTRYPOINT/CMD in Dockerfile 到点 到正确 executable
Ensure 所有必需配置 files and 环境变量是 provided
添加错误 logging at 开始的 你的 application 到 catch startup 错误
测试容器 locally 之前 deploying 到 cluster
如何预防
总是测试容器 locally 之前 pushing 到 production
Use health 检查端点到 验证 startup 成功
Log startup steps 所以 failures 是简单到 diagnose