Docker Heredoc "unexpected end of statement while looking for matching" in CI
BuildKit parsed a heredoc RUN <<EOF block and reached the end of the file without finding its closing EOF. The block is unterminated, or heredocs are not enabled for this Dockerfile.
What this error means
The build fails at parse time with unexpected end of statement while looking for matching heredoc "EOF". No steps run because the Dockerfile never finished parsing the heredoc body.
ERROR: failed to solve: dockerfile parse error: unexpected end of statement
while looking for matching heredoc "EOF"
# the RUN <<EOF block was never closed by a line containing only EOFCommon causes
Missing or misindented terminator
The closing EOF must be on its own line with no leading whitespace (unless using <<-EOF). A trailing space, indentation, or a typo means the parser never sees the terminator.
Heredoc syntax without the syntax directive
Heredocs need a recent Dockerfile frontend. Without # syntax=docker/dockerfile:1 at the top (on older BuildKit), the <<EOF is not understood as a heredoc.
Mismatched delimiter name
Opening with <<EOF but closing with a different word (END, eof) leaves the heredoc open until end of file.
How to fix it
Close the heredoc on its own line
Enable the syntax frontend and terminate the block with an unindented delimiter.
# syntax=docker/dockerfile:1
RUN <<EOF
set -e
apt-get update
apt-get install -y curl
EOFUse <<-EOF if you must indent the terminator
The dash form strips leading tabs so an indented EOF still closes the block.
RUN <<-EOF
set -e
echo hi
EOFHow to prevent it
- Add
# syntax=docker/dockerfile:1when using heredocs. - Keep the closing delimiter on its own line with no leading spaces.
- Match the opening and closing delimiter words exactly.