[][src]Crate dockerfile_parser

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.

CopyFlag

A key/value pair passed to a COPY instruction as a flag.

CopyInstruction

A Dockerfile COPY instruction.

Dockerfile

A parsed Dockerfile.

EnvInstruction

A Dockerfile ENV instruction.

EnvVar

An environment variable key/value pair

FromInstruction

A Dockerfile FROM instruction.

ImageRef

A parsed docker image reference

Label

A single label key/value pair.

LabelInstruction

A Dockerfile LABEL instruction.

MiscInstruction

A miscellaneous (unsupported) Dockerfile instruction.

Span

A byte-index tuple representing a span of characters in a string

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].

Enums

CmdInstruction

A Dockerfile CMD instruction.

EntrypointInstruction

A Dockerfile ENTRYPOINT instruction.

Error

A Dockerfile parsing error.

Instruction

A single Dockerfile instruction.

Rule
RunInstruction

A Dockerfile RUN instruction.

StageParent

The parent image of a Docker build stage

Type Definitions

Result

A Dockerfile parsing Result.