Format Dockerfile keywords while keeping heredoc content
Admin ·
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.
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.
| Text in the example | Formatted result |
|---|---|
| from alpine:3.22 AS files | FROM alpine:3.22 AS files |
| from this line is literal | Unchanged heredoc body |
| # this is file content | Unchanged heredoc body |
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.
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.