Minimal, educational container-like environment using chroot and mount namespaces.
This tool constructs a tiny root filesystem with a handful of userland tools and their required shared libraries, then starts a bash shell inside a new mount namespace and chroot. It is intended for learning, not production isolation.
- Builds a rootfs under
tmp/rootfswith basic directories and copies selected binaries (e.g.,bash,ls,cp, etc.). - Resolves linked libraries via
lddand copies them, plus the ELF interpreter, into the rootfs. - Launches a child process in a new mount namespace,
chroots into the rootfs, mountsproc,sysfs, and attemptsdevtmpfs(or creates a few device nodes if that fails). - Spawns
/bin/bashinside the chroot with a minimalPATH.
- Linux host with
sudoavailable - Go toolchain (as specified in
go.mod) lddon PATH (usually provided by glibc)
make buildThis produces the ship binary at the repo root.
Running requires root privileges for namespaces, mounts, device nodes, and chroot:
sudo ./ship childAlternatively, use the Makefile target:
make runYou should land in a bash shell inside the new rootfs. Type exit to leave.
Unmount mounted filesystems and remove the temporary rootfs:
make cleantmpRemove the built binary:
make clean- build:
go build -o ship cmd/main.go - run:
sudo ./ship child - cleantmp: Unmounts
proc,sys,devif mounted undertmp/rootfsand removes the directory - clean: Removes the
shipbinary
cmd/
main.go # entrypoint; wires rootfs creation and child exec
internal/
rootfs/
rootfs.go # builds the minimal root filesystem
chroot/
chroot.go # chroot, mounts, and child shell exec
utils/
utils.go # small file/dir helpers
Makefile # build/run/cleanup helpers
- This is not a container runtime and provides limited isolation. It uses only mount namespaces and chroot.
sudois required; ensure you trust the code you run as root.- On some distributions,
devtmpfsmay be restricted; the tool falls back to creating a few device nodes. - TERM and terminfo: if
TERMis set, a matching terminfo entry is copied to improve shell UX.
- Shell fails to start or is blank: ensure
bashexists on host andlddis available. - Permission errors: re-run with
sudo. - Garbled terminal: try
export TERM=xterm-256coloron host before running; or verify terminfo was copied. - Cleanup issues: if
make cleantmpreports busy mounts, ensure no process is still running inside the chroot.