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

dockerfile-parser-rs

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

6 releases

Uses new Rust 2024

new 0.3.0 Apr 18, 2025
0.2.1 Apr 18, 2025
0.1.2 Apr 17, 2025

#314 in Unix APIs

Download history 129/week @ 2025-04-05 170/week @ 2025-04-12

299 downloads per month

MIT license

34KB
808 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
  • SHELL
  • 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