docker config_error ai_generated true

解析 Dockerfile 失败:意外的文件结尾,期望 FROM

failed to parse Dockerfile: unexpected end of file, expected from

ID: docker/dockerfile-parse-error-missing-from

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2023-09-05首次发现

版本兼容性

版本状态引入弃用备注
Docker 24.0.5 active
Docker 25.0.2 active

根因分析

Dockerfile 为空或没有以 FROM 指令开头,FROM 是第一个非注释行所必需的。

English

The Dockerfile is empty or does not start with a FROM instruction, which is mandatory as the first non-comment line.

generic

官方文档

https://docs.docker.com/engine/reference/builder/#from

解决方案

  1. Ensure Dockerfile starts with a valid FROM instruction, e.g.: FROM ubuntu:22.04
  2. Check if Dockerfile is empty: cat Dockerfile. If empty, add FROM instruction.
  3. Use -f flag to specify a non-standard Dockerfile path: docker build -f /path/to/Dockerfile .

无效尝试

常见但无效的做法:

  1. # comment 80% 失败

    Adding a comment before FROM is allowed, but an empty file or missing FROM still fails.

  2. FROM scratch 70% 失败

    Using a different base image syntax (e.g., 'FROM scratch') is valid, but if missing entirely it still fails.