Configuration guides

Format Dockerfile keywords while keeping heredoc content

·

A Dockerfile instruction and a line inside a heredoc have different roles. The formatter changes the visual spelling of supported instructions and keeps the embedded text in its original form.

Dockerfile Formatter

Compare instructions with the copied file's contents

Select Load example and Format Dockerfile. The first actual from instruction becomes FROM. The later line from this line is literal belongs to the COPY heredoc, so it stays lowercase.

The two spaces and hash inside "ready # literal" stay inside the same JSON argument. The comment-like line inside the heredoc also stays exactly as written.

Compare instructions with the copied file's contents
Text in the exampleFormatted result
from alpine:3.22 AS filesFROM alpine:3.22 AS files
from this line is literalUnchanged heredoc body
# this is file contentUnchanged heredoc body

Dockerfile referenceDockerfile here-document syntax

Choose whether to remove instruction margins

Turn off Remove margins before instruction names. The keyword still becomes uppercase and the instruction's incoming leading spaces remain.

For an original CRLF copy, use Open UTF-8 Dockerfile and format it without editing the source field. Download Dockerfile.formatted and compare its line endings and argument text with the input.

Dockerfile referenceBuildKit v0.22 Dockerfile parser

Review unsupported syntax before formatting

A custom frontend can give unfamiliar lines meaning outside the standard Dockerfile grammar. The formatter stops when it cannot safely identify a supplied frontend or a heredoc boundary.

Review the reported line. For a supported heredoc, a literal marker such as <<EOF or <<-'EOF' introduces a body with a matching ending line. Recheck the source when you can establish that boundary.

Dockerfile here-document syntaxBuildKit v0.22 Dockerfile parser

Common questions

Why does formatting leave argument spacing alone?

Spaces and continued text can affect the argument passed to a command. The formatter confines its changes to the instruction keyword and its optional leading margin.

What if I paste a Dockerfile instead of opening it?

The tool formats the line endings received from the editor. Use an unedited file opened with the file picker to keep the original UTF-8 line endings.

Sources

Put it into practice.

Related guides