Crates.io | dockerfile-parser-rs |
lib.rs | dockerfile-parser-rs |
version | 3.2.1 |
created_at | 2025-04-11 09:48:15.92975+00 |
updated_at | 2025-09-13 09:21:27.455418+00 |
description | The ultimate Rust library for parsing, modifying, and generating Dockerfiles |
homepage | |
repository | https://github.com/slimreaper35/dockerfile-parser-rs |
max_upload_size | |
id | 1629568 |
size | 83,798 |
The ultimate Rust library for parsing, modifying, and generating Dockerfiles.
Note: In addition to the official Dockerfile instructions, empty lines and comments are supported too.
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;
use dockerfile_parser_rs::ParseResult;
fn main() -> ParseResult<()> {
let path = PathBuf::from("./Dockerfile");
let mut dockerfile = Dockerfile::from(path.clone())?;
dockerfile.instructions.push(Instruction::User {
user: String::from("1001"),
group: None,
});
dockerfile.dump(path)?;
Ok(())
}
Run the following Cargo command in your project directory:
cargo install dockerfile-parser-rs
Example:
# prints the Dockerfile as JSON
dockerfile-parser-rs ./Dockerfile
The instructions are not case-sensitive. However, the library works only with uppercase instructions for simplicity and consistency. Using uppercase instructions is also a recommended convention in Dockerfile format documentation.
Options for all instructions will be sorted in alphabetical order. This is done to ensure
deterministic output when dumping a Dockerfile. The same applies to the ARG
, ENV
, and LABEL
instructions when they have multiple key-value pairs defined on one line.
Here-documents allow redirection of subsequent Dockerfile lines to the input of RUN
or COPY
commands. If such a command contains a here-document, the Dockerfile considers the next lines until
the line only containing a here-doc delimiter as part of the same command.
The here-documents syntax is only supported for the RUN
instruction and only with the EOF
delimiter. Make sure that here-documents are always terminated with an EOF
character on a new
line.