Skip to content

Legacy ENV key value with a multi-word value becomes an invalid key=value #69

Closed

Description

@gaborbernat

Converting a legacy ENV key value instruction to the key=value form breaks when the value contains spaces. The output is not a valid Dockerfile: docker build rejects it, and so does dockerfmt on the next run.

Reproduce

FROM alpine
ENV JAVA_OPTS -Xms256m -Xmx512m
dockerfmt Dockerfile

Actual

FROM alpine
ENV JAVA_OPTS=-Xms256m -Xmx512m

The original builds and sets JAVA_OPTS=-Xms256m -Xmx512m. docker build on the output, and dockerfmt run on it again, both fail with:

Error parsing file: Syntax error - can't find = in "-Xmx512m". Must be of the form: name=value

Expected

In the legacy form everything after the key is the value, so the converted instruction needs quotes:

ENV JAVA_OPTS="-Xms256m -Xmx512m"

Leaving the instruction in its legacy form would also be correct.

Impact

With --write the Dockerfile no longer builds. In a sample of about 450 real-world Dockerfiles, 112 lines used the legacy ENV form and one of them had an unquoted multi-word value.

Reproduced with v0.5.4 and with main at a5868c2.

Activity

  1. RyoKusnadi commented on Nov 5, 2026

    @RyoKusnadi
    Contributor

    @reteps I opened #74 for this. Could you please review it when you have a moment? Thank you!

  2. added a commit that references this issue on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions