#docker #dockerfile


A Rust library for dynamically generating Dockerfiles

4 releases

0.2.1 Dec 10, 2018
0.2.0 Dec 9, 2018
0.1.1 Dec 9, 2018
0.1.0 Dec 9, 2018

#270 in Development tools

Download history 360/week @ 2021-01-09 490/week @ 2021-01-16 399/week @ 2021-01-23 1518/week @ 2021-01-30 1737/week @ 2021-02-06 5104/week @ 2021-02-13 1132/week @ 2021-02-20 5384/week @ 2021-02-27 9196/week @ 2021-03-06 15110/week @ 2021-03-13 7162/week @ 2021-03-20 5114/week @ 2021-03-27 5846/week @ 2021-04-03 8278/week @ 2021-04-10 8362/week @ 2021-04-17 3143/week @ 2021-04-24

6,172 downloads per month


688 lines


Build Status Crates.io docs.rs License Crates.io Crates.io

A Rust library for dynamically generating Dockerfiles.

The use case this crate was originally built for was to build Docker images from a worker service running in Kubernetes for client workloads. This is definitely not the only pattern that is supported. The generated Dockerfiles could be persisted somewhere or discarded immediately after use. The containers generated are standard containers, built according to the Dockerfiles you generated.

All of the Dockerfile instructions are supported in raw form as of 2018.12.09. There is an issue open to add more structured and type-safe interfaces for the instructions which need it.

get started

First you will need to add this to your Cargo.toml dependencies.

dockerfile = "0.2"

Now you can start building Dockerfiles.

use dockerfile::{

fn main() {
    // Build up a new Dockerfile.
    let dockerfile = Dockerfile::base("rust:${RUST_VERSION}-slim")
        .push(Copy::new("/static ./static"))
        .push(Cmd::new("echo 'Hello. Goodbye.'"))

    // Write it out as a string.
    let output = dockerfile.to_string();
FROM rust:${RUST_VERSION}-slim
COPY /static ./static
CMD echo 'Hello. Goodbye.'


I would like to have this crate offer a type-safe interface for constructing the various Dockerfile instructions. This will help reduce bugs which could only be found once you actually attempt to invoke the docker build. I would like to experiment with adding constructors for the various forms of instructions; EG, offer a constructor for CMD which takes an impl Iterator<Item=AsRef<str>> for building the form CMD ["arg0", "arg1"] &c.

No runtime deps


  • docinclude