Skip to content
Latchkey

Docker "ENV value with spaces not quoted" build error in CI

In the multi-variable ENV key=value form, Docker splits on whitespace. An unquoted value that contains a space is read as the start of a second key=value, so either the build errors or the variable ends up truncated.

What this error means

A build fails at an ENV line, or a later step sees a truncated value. The value contained an unquoted space.

docker
ERROR: failed to solve: dockerfile parse error on line 7: ENV must have two arguments
# from: ENV APP_NAME=My Cool App

Common causes

A space in the value without quotes

In ENV APP_NAME=My Cool App, Cool App is parsed as further tokens, not part of the value.

Mixing the two ENV forms

The legacy ENV key value form and the key=value form behave differently with spaces; mixing them yields surprising splits.

How to fix it

Quote the value

  1. Wrap any value containing spaces in double quotes.
  2. Keep one key="value" per token in the multi-variable form.
Dockerfile
ENV APP_NAME="My Cool App"
ENV GREETING="Hello world" LOCALE="en_US"

Escape spaces if you cannot quote

  1. Backslash-escape the spaces in the value as an alternative to quoting.
Dockerfile
ENV APP_NAME=My\ Cool\ App

How to prevent it

  • Always quote ENV/ARG values that contain spaces.
  • Prefer the key="value" form consistently.
  • Lint Dockerfiles with hadolint to catch unquoted values.

Related guides

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