Skip to content

Detect if code is running inside a chroot environment.

License

Notifications You must be signed in to change notification settings

PicoJr/inside-chroot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inside-chroot

⚠️ After further testing it appears this technique is quite unreliable (e.g. it does not work with some earlier Docker versions). Use at your own risk.

Detect if code is running inside a chroot environment.

How does it work

Retrieve inode for / if it is not 2 assume code runs inside chroot.

API

use inside_chroot::inside_chroot;
let inside = inside_chroot().unwrap();
assert!(!inside) // may fail if tests are run inside a chroot env

Example

Outside chroot

cargo run --example inside-root
currently not inside chroot

Inside a docker container (chroot)

# compiles inside-chroot example binary
cargo build --example inside-chroot
# start a docker container
docker run -it -v ${PWD}/target/debug/examples/:/examples archlinux:latest /examples/inside-chroot 
currently inside chroot 

Credits

License

Dual-licensed under MIT or the Apache License V2.0.

About

Detect if code is running inside a chroot environment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages