docker-core-tech-chroot
Chroot
Introduction
Every process/command
in Linux/Unix like systems has a current working directory called root directory
. chroot changes the root directory for current running process as well as its children.
it creates a virtualized environment in a Unix(linux) operating system, separating it from the main operating system’s directory structure. This process essentially generates a confined space with its own root directory, to run software programs. This virtual environment runs separately from the main operating system's root directory.
Any software program run in this environment can only access files within its own directory tree. It cannot access files outside of that directory tree. This confined virtual environment is often called a "chroot jail".
Use cases
- Privilege separation for unprivileged process such as Web-server or DNS server.
- Setting up a test environment.
- Run programs or ABI in-compatibility programs without crashing application or system. different apps in the same system can use different libraries, it’s what container image needs.
- System recovery.
- Reinstall the bootloader such as Grub or Lilo.
- Password recovery – Reset a forgotten password and more.
Example to use chroot
Two ways to change root directory
chroot()
system call(binary with CAP_SYS_CHROOT capability)chroot linux command
(super user)
let's use chroot as the example to show how we should do on linux
1 | # format: |
1 | $ mkdir /tmp/new_root |
here we just copy bash, if you run ls, you need to copy ls and it dependency as well