LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format
is a build-check warning, and the build still succeeds. It means a line such as
ENV GREETING hello uses the old space-separated form. Write
ENV GREETING=hello and the warning is gone.
The change is one character per line: put = between the name and the value,
and quote the value if it contains spaces.
The error
1 warning found (use docker --debug to expand):
- LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 2)
The build exited with code 0 and the RUN echo $GREETING step after the line ran
normally. The terminal colour codes in the captured lines are left out. The warning names
the line, here line 2, so in a long Dockerfile with several ENV lines you can
go straight to the one that uses the old spelling and leave the others alone.
Why it happens
Dockerfiles accept two spellings of ENV. The old one, ENV name value,
takes everything after the first space as the value of a single variable. The newer one,
ENV name=value, can set several variables on one line. Docker's build checks
flag the old form as a warning while the file is parsed.
A second test file showed both behaviours. With ENV OLDSTYLE hello world and
ENV GREETING="hello world" TARGET=two, the next step printed
OLDSTYLE=[hello world] GREETING=[hello world] TARGET=[two], and the build warned
about line 2 only. The old form is easy to misread as two names; the = form
makes the boundary between name and value explicit.
The fix
FROM alpine
ENV GREETING=hello
RUN echo $GREETING
Built with the same command, the log had no warning section. The broken file was identical
except for line 2, ENV GREETING hello. For a value with spaces, quote it in the
new form, as in ENV GREETING="hello world" from the second test.
How it was reproduced
A three-line Dockerfile on alpine, built with
docker build --progress=plain -t fix8-bld-q3 fix8-bld-q3 on Docker Desktop with
engine 29.9.2 and its default BuildKit builder, then the fixed file built into
fix8-bld-q3fix. Tags and folders are this test's own.
Frequently asked
- Does LegacyKeyValueFormat fail the Docker build?
- No. It is a warning printed after the build, which exits with code 0. The variable is set as before.
- How do I fix ENV key value format in a Dockerfile?
- Add an equals sign between the name and the value, for example ENV GREETING=hello instead of ENV GREETING hello.
- Can one ENV line set several variables?
- Yes, in the key=value form: list several name=value pairs on the same ENV line, separated by spaces.
More decoded errors in the Fixes category, including the FromAsCasing warning from the same build checks.