9 releases
0.1.8 | Feb 7, 2024 |
---|---|
0.1.7 | Feb 6, 2024 |
0.1.1 | Jan 31, 2024 |
#27 in #namespaces
137 downloads per month
37KB
912 lines
sbox
Tiny Linux containers implementation.
Usage
fn main() {
// Create user namespace mapper for current user with subuids and subgids.
let user_mapper = NewIdMap::new_root_subid(getuid(), getgid()).unwrap();
// Create container manager.
let manager = Manager::new("/tmp/sbox", "/sys/fs/cgroup/sbox", user_mapper).unwrap();
// Create container.
let mut container = manager
.create_container(
"example".into(),
ContainerConfig {
layers: vec!["/tmp/sbox-rootfs".into()],
..Default::default()
},
)
.unwrap();
// Start container.
let process = container
.start(ProcessConfig {
command: vec!["/bin/sh".into(), "-c".into(), "echo 'Hello, World!'".into()],
..Default::default()
})
.unwrap();
// Wait for init process exit.
process.wait(None).unwrap();
// Remove all container resources.
container.destroy().unwrap();
}
License
sbox is distributed under the terms of both the MIT license and the Apache 2.0 License.
Dependencies
~3–13MB
~149K SLoC