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§
- A Dockerfile
ARGinstruction. - A Docker string that may be broken across several lines, separated by line continuations (
\\\n), and possibly intermixed with comments. - A Dockerfile
CMDinstruction. - A key/value pair passed to a
COPYinstruction as a flag. - A Dockerfile
COPYinstruction. - A parsed Dockerfile.
- A Dockerfile
ENTRYPOINTinstruction. - A Dockerfile
ENVinstruction. - An environment variable key/value pair
- A key/value pair passed to a
FROMinstruction as a flag. - A Dockerfile
FROMinstruction. - A parsed docker image reference
- A single label key/value pair.
- A Dockerfile
LABELinstruction. - A miscellaneous (unsupported) Dockerfile instruction.
- A Dockerfile
RUNinstruction. - A byte-index tuple representing a span of characters in a string
- A comment with a character span.
- A string with a character span.
- A utility to repeatedly replace spans of text within a larger document.
- A single stage in a multi-stage build.
- A collection of stages in a [multi-stage build].
- A string array (ex. [“executable”, “param1”, “param2”])
Enums§
- A component of a breakable string.
- A Dockerfile parsing error.
- A single Dockerfile instruction.
- A string that may be broken across many lines or an array of strings.
- The parent image of a Docker build stage
Type Aliases§
- A Dockerfile parsing Result.