#dockerfile #docker #parser #library #entry-point #work-dir

dockerfile-parser-rs

The ultimate Rust library for parsing, modifying, and generating Dockerfiles

2 releases

Uses new Rust 2024

new 0.1.1 Apr 11, 2025
0.1.0 Apr 11, 2025

#355 in Unix APIs

MIT license

28KB
717 lines

dockerfile-parser-rs

Version

The ultimate Rust library for parsing, modifying, and generating Dockerfiles.

Instructions

  • ADD
  • ARG
  • CMD
  • COPY
  • ENTRYPOINT
  • ENV
  • EXPOSE
  • FROM
  • LABEL
  • RUN
  • USER
  • VOLUME
  • WORKDIR

Note: In addition to the official supported Dockerfile instructions, this library also supports placeholders for empty lines and comments.

Install

Run the following Cargo command in your project directory:

cargo add dockerfile-parser-rs

Example

use std::path::PathBuf;

use dockerfile_parser_rs::Dockerfile;
use dockerfile_parser_rs::Instruction;

fn main() {
    let mut dockerfile = Dockerfile::from(PathBuf::from("Dockerfile")).unwrap();

    dockerfile.instructions.push(Instruction::User {
        user: String::from("1001"),
        group: None,
    });

    dockerfile.dump().unwrap();
}

Dependencies

~2.4–4MB
~72K SLoC