dockerfmt

dockerfmt 是一个 Dockerfile 格式化和解析器,是 dockfmt 的一个现代版本。它构建于内部的 buildkit 解析器之上。

安装

二进制文件可从 releases 页面获取。

用法

A updated version of the dockfmt. Uses the dockerfile parser from moby/buildkit and the shell formatter from mvdan/sh.
Usage:
 dockerfmt [Dockerfile] [flags]
 dockerfmt [command]
Available Commands:
 completion Generate the autocompletion script for the specified shell
 help    Help about any command
 version   Print the version number of dockerfmt
Flags:
 -c, --check     Check if the file(s) are formatted
 -h, --help     help for dockerfmt
 -i, --indent uint  Number of spaces to use for indentation (default 4)
 -n, --newline    End the file with a trailing newline
 -w, --write     Write the formatted output back to the file(s)
Use "dockerfmt [command] --help" for more information about a command.

局限性

欢迎贡献代码!

特性

RUN <<EOF
echo "hello"
echo "world"
EOF
RUN echo "hello" \
  # this is a comment
  && echo "world"
RUN echo "hello" \
  # this is a comment
  # that spans multiple lines
  && echo "world"

这令人惊讶地 non-trivial,因为我们希望将注释附加到格式化输出中的位置,但它们事先被解析器剥离了。

JS Bindings

JS bindings 在 js 目录中可用。 有关如何使用它们的更多信息,请参见 README 文件。

关于

Dockerfile format and parser. a modern dockfmt.