首页/云/云与容器速查/容器启动失败排查五步

容器启动失败排查五步

容器起不来按固定顺序走:看状态 → 看日志 → inspect 配置 → 校验 entrypoint/cmd → 手动换 shell 验证。先复现最小现场,再谈改配置。

云与容器速查云更新于 2026-10-12
第 1 步docker ps -a 看状态与退出码
第 2 步docker logs <容器> --tail=200 看输出
第 3 步docker inspect 看 Config/State/Mounts 是否符合预期
第 4 步docker run --entrypoint sh 或覆盖 command 验证镜像本身
第 5 步对齐宿主环境:端口、路径、权限、资源

排查命令组

排查命令组
docker ps -a | head
docker logs myapp --tail=200
docker inspect myapp | head -60
docker run --rm -it --entrypoint sh myapp:1.2.3   # 绕开默认入口检查环境
『镜像在 A 机器能跑 B 机器不能』重点查:架构(exec format error)、挂载路径、宿主内核版本、资源限制。

易错点

  • 只看 logs 不看 inspect:挂载/端口/入口配置错了,日志里根本没有
  • 在错误镜像上调试:先 docker images 核对 tag 是不是要查的那个

数据来源与参考

  • Docker Docs:Troubleshooting
  • Docker Docs:Start containers automatically

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌