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 AppCommon 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
- Wrap any value containing spaces in double quotes.
- 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
- Backslash-escape the spaces in the value as an alternative to quoting.
Dockerfile
ENV APP_NAME=My\ Cool\ AppHow 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
Docker "dockerfile parse error" - Fix Dockerfile Syntax in CIFix Docker "failed to solve: dockerfile parse error" in CI - unknown instructions, bad line continuations, or…
Docker "UndefinedVar: Usage of undefined variable" in Build ARG/ENVFix Docker BuildKit "UndefinedVar: Usage of undefined variable \$X" in CI - an ARG referenced before declarat…
Docker Heredoc "unexpected end of statement while looking for matching" in CIFix BuildKit heredoc "unexpected end of statement while looking for matching heredoc" in CI - a RUN <<EOF blo…