First we will create a small program in Rust that will:
- print its
pid - list all the files and directories in
/
use std::{ fs, process };
fn main() {
println!("{}", process::id());
let paths = fs::read_dir("/").unwrap();
for path in paths {
println!("Name: {}", path.unwrap().path().display())
}
}We can now statically build this program: RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu.
Let's now create a new cargo project: cargo new mocker (mocker -> mock docker)
Let's build mocker a small docker clone interatively:
- Make it so that
mocker ./pidwill run the binary and show its output. - Make it so that running
mocker ./pidshows1as its pid
tip
When you execute the binary, give it a new pid namespace https://docs.rs/nix/0.26.2/nix/sched/struct.CloneFlags.html#associatedconstant.CLONE_NEWPID use namespaces- Make it so that running
mocker ./pidwill makepidlist files from the current directory