Configuration guides

Read Dockerfile findings for exec arguments and build stages

·

Use the static checker to find a concrete instruction before you try to build. The worked example separates an exec argument problem from a stage reference problem.

Dockerfile Validator

Read the two sample findings

Select Load example and Check Dockerfile. Line 3 contains a number in the RUN exec array. Dockerfile exec-form arguments are strings, even when the command expects to interpret a number.

Line 5 asks for COPY --from=3. The two stages are numbered 0 and 1, so index 3 has no corresponding stage within this file.

Read the two sample findings
LineProblemOne correction
3Nonstring JSON argumentWrite "7" as a string
5Numeric stage index exceeds the stage listUse --from=build

Dockerfile referenceDockerfile shell and exec formsDocker multi-stage builds

Open the report after making the two edits

Quote the 7, replace --from=3 with --from=build and select Check Dockerfile. The output reports that the structure passed for two stages.

Download dockerfile-report.json. The findings array should be empty. Named source images or supplied named contexts may also be valid COPY sources, so check their availability separately.

Dockerfile shell and exec formsDocker multi-stage builds

Read the boundary of the supplied text

The checker follows early parser directives, logical continuation lines and supported literal heredoc boundaries. It does not interpret the commands in a RUN line.

A successful structure report covers the listed syntax checks. Actual copying and building depend on the context files, frontend, platform, images and command behavior.

Dockerfile referenceBuildKit v0.22 Dockerfile parser

Common questions

Why can a shell-form RUN line start with a bracket?

A shell command can begin with the test operator [. A JSON exec array is a separate instruction form. The checker looks for clear JSON array syntax or intent.

What if a heredoc has no closing line?

The checker reports the opening instruction. Add the matching delimiter on a line by itself. With <<-, leading tabs on the closing line are allowed.

Sources

Put it into practice.

Related guides