Skip to content
Latchkey

Docker "failed to solve: dockerignore parse error" in CI

BuildKit compiles .dockerignore into a pattern matcher before sending the context. A pattern it cannot parse - a stray bracket, a malformed negation, or an illegal path syntax - fails the whole build before any layer is built.

What this error means

A docker build/buildx build aborts very early with failed to solve: dockerignore parse error or error checking context: can't parse .dockerignore.

docker
ERROR: failed to solve: dockerignore parse error: syntax error in pattern

Common causes

An unbalanced bracket or wildcard

A pattern like src/[a-z with an unclosed character class cannot compile.

A misplaced negation

A bare ! with no following pattern, or a negation before any include, confuses the parser.

A non-UTF8 or CRLF-mangled file

Carriage returns or stray bytes can produce patterns the matcher rejects.

How to fix it

Write valid ignore patterns

  1. Close any character classes and remove stray punctuation.
  2. Put a real pattern after every ! negation.
.dockerignore
# .dockerignore
node_modules
**/*.log
!keep.log
src/[a-z]*.tmp

Normalize line endings to LF

  1. Convert the file to Unix line endings to drop stray CR bytes.
Terminal
sed -i 's/\r$//' .dockerignore

How to prevent it

  • Keep .dockerignore LF-only and free of unbalanced wildcards.
  • Test a context build locally after editing ignore patterns.

Related guides

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