Expand description
§Rust parser for Dockerfile syntax
A pure Rust library for parsing and inspecting Dockerfiles, useful for performing static analysis, writing linters, and creating automated tooling around Dockerfiles. It can provide useful syntax errors in addition to a full syntax tree.
§Quick start
use dockerfile_parser::Dockerfile;
let dockerfile = Dockerfile::parse(r#"
FROM alpine:3.11 as builder
RUN echo "hello world" > /hello-world
FROM scratch
COPY --from=builder /hello-world /hello-world
"#).unwrap();
for stage in dockerfile.iter_stages() {
println!("stage #{}", stage.index);
for ins in stage.instructions {
println!(" {:?}", ins);
}
}
Structs§
- ArgInstruction
- A Dockerfile
ARG
instruction. - Breakable
String - A Docker string that may be broken across several lines, separated by line
continuations (
\\\n
), and possibly intermixed with comments. - CmdInstruction
- A Dockerfile
CMD
instruction. - Copy
Flag - A key/value pair passed to a
COPY
instruction as a flag. - Copy
Instruction - A Dockerfile
COPY
instruction. - Dockerfile
- A parsed Dockerfile.
- Entrypoint
Instruction - A Dockerfile
ENTRYPOINT
instruction. - EnvInstruction
- A Dockerfile
ENV
instruction. - EnvVar
- An environment variable key/value pair
- From
Flag - A key/value pair passed to a
FROM
instruction as a flag. - From
Instruction - A Dockerfile
FROM
instruction. - Image
Ref - A parsed docker image reference
- Label
- A single label key/value pair.
- Label
Instruction - A Dockerfile
LABEL
instruction. - Misc
Instruction - A miscellaneous (unsupported) Dockerfile instruction.
- RunInstruction
- A Dockerfile
RUN
instruction. - Span
- A byte-index tuple representing a span of characters in a string
- Spanned
Comment - A comment with a character span.
- Spanned
String - A string with a character span.
- Splicer
- A utility to repeatedly replace spans of text within a larger document.
- Stage
- A single stage in a multi-stage build.
- Stages
- A collection of stages in a [multi-stage build].
- String
Array - A string array (ex. [“executable”, “param1”, “param2”])
Enums§
- Breakable
String Component - A component of a breakable string.
- Error
- A Dockerfile parsing error.
- Instruction
- A single Dockerfile instruction.
- Rule
- Shell
OrExec Expr - A string that may be broken across many lines or an array of strings.
- Stage
Parent - The parent image of a Docker build stage
Functions§
- substitute
- Given a map of key/value pairs, perform variable substitution on a given
input string.
max_recursion_depth
controls the maximum allowed recursion depth if variables refer to other strings themselves containing variable references. A small number but reasonable is recommended by default, e.g. 16. If None is returned, substitution was impossible, either because a referenced variable did not exist, or recursion depth was exceeded.
Type Aliases§
- Result
- A Dockerfile parsing Result.