Skip to content
Latchkey

Docker "dockerfile parse error" - Fix Dockerfile Syntax in CI

BuildKit could not parse the Dockerfile itself - before running any step. The error names a line and column; the fix is almost always right there.

What this error means

The build fails instantly with dockerfile parse error on line N or unknown instruction. No RUN/COPY steps execute because the file never parsed.

docker build output
ERROR: failed to solve: dockerfile parse error on line 12: unknown instruction: RUNN
# or: unexpected end of statement while looking for matching ...

Common causes

Misspelled or unknown instruction

A typo like RUNN, FORM, or COPPY, or a directive that is not a real Dockerfile instruction, makes the parser reject the line.

Broken line continuation

A trailing backslash followed by a space, a missing backslash on a multi-line RUN, or Windows CRLF line endings can corrupt the continuation and confuse the parser.

Misplaced parser directive or heredoc

# syntax= or other parser directives must appear at the very top. A heredoc (RUN <<EOF) without a matching terminator also fails to parse.

How to fix it

Go to the reported line and fix the syntax

  1. Open the Dockerfile at the line/column in the error.
  2. Correct the instruction spelling and ensure each line continuation ends with a single backslash and no trailing whitespace.
  3. Move any # syntax= directive to the very first line.

Normalize line endings and validate

Convert CRLF to LF and re-run with plain output to see the exact failing line.

Terminal
sed -i 's/\r$//' Dockerfile
docker build --progress=plain .

How to prevent it

  • Lint Dockerfiles in CI (e.g. hadolint) before building.
  • Enforce LF line endings via .gitattributes for Dockerfiles.
  • Keep multi-line RUN blocks tidy with one backslash per continued line.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →