-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.rs
28 lines (23 loc) · 851 Bytes
/
demo.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() {
let c =
lxc::Container::new("apicontainer", None).expect("Failed to setup lxc_container struct");
if !c.is_defined() {
c.create(
Some("download"),
None,
None,
lxc::CreateFlags::QUIET,
&["-d", "ubuntu", "-r", "focal", "-a", "amd64"],
)
.expect("Failed to create container rootfs");
}
c.start(false, &[]).expect("Failed to start the container");
println!("Container state: {}", c.state());
println!("Container PID: {}", c.init_pid());
println!("Interfaces: {:?}", c.get_interfaces());
if c.shutdown(30).is_err() {
println!("Failed to cleanly shutdown the container, forcing.");
c.stop().expect("Failed to kill the container.");
}
c.destroy().expect("Failed to destroy the container.");
}