The plan
The mini container has three parts. The first is a root filesystem, a directory that contains everything the program needs, such as a shell and its libraries. The second is a set of namespaces that hide the host's process list, host name, and mounts from the program. The third is a launch command that enters the root with chroot and starts the shell. The lab builds the first part and writes the second and third as a script, and it checks the syntax without requiring the namespaces to be created.
Build the root filesystem
A root filesystem needs directories with standard names: bin for programs, etc for configuration, and proc as the mount point for the process filesystem. Create them under a directory called rootfs, and write a host name file so that the box identifies itself.
mkdir -p rootfs/bin rootfs/proc rootfs/etc
echo mini > rootfs/etc/hostnameA real root filesystem also needs programs. A common choice is a static build of BusyBox, which packs a shell and the usual utilities into one binary that has no shared library dependencies. A static binary is the simplest choice for chroot, because the new root does not need copies of the libraries. The lab does not copy a binary, but the same layout works with one placed in rootfs/bin.
Ask for namespaces
The launcher calls unshare with the flags that create the isolation. --uts gives the box its own host name, --mount keeps mounts private to it, and --pid --fork gives it its own process numbering. The --fork flag matters, because the first process in a new PID namespace must be the one that becomes PID 1 inside it.
A hostname change inside the box should not affect the host. That is the simplest test of the UTS namespace, and it is cheap to run on a machine where you have the privilege.
Enter the root
After unshare, the launcher calls chroot to set the new root, and then runs the shell. The path /workspace/rootfs is the directory the shell sees as /. Inside, the shell can list bin and etc, and it cannot reach the host files above the root through an absolute path. Remember that chroot is not a full sandbox, so the namespaces and the directory layout do the isolation work together.
The script
A short script is easier to repeat than a long command. The script sets the strict options, calls unshare with the flags, and passes the chroot and shell at the end. Each line is one step, so a failure points at one step.
#!/bin/bash
set -eu
unshare --uts --mount --pid --fork chroot /workspace/rootfs /bin/shIn the lab, running this script is optional. An unprivileged user usually cannot create these namespaces, and the error is a useful result. The step that matters is the syntax check, which bash -n performs without running any command.
Check before you run
bash -n reads a script, parses it, and reports syntax errors. It does not expand variables or run commands, so it is safe to use on a script that would fail or change the system. A clean result means the script is at least well formed, which catches missing quotes and unbalanced if statements early.
A syntax check does not prove the script works. It does not check that the binaries exist, that the paths are right, or that you have privilege. Those are runtime checks, and the step that follows the build is to run the script on a machine where the privilege exists.
What you built
The directory is the filesystem, the flags are the isolation, and the command is the process. Real container runtimes add cgroup limits, a pivot_root instead of chroot, dropped capabilities, and a seccomp filter. Each addition is one more kernel setting, and you now know where to look for each one.
Testing the result
Once the script runs on a machine that allows namespaces, test each feature separately. Inside the box, run hostname and compare it with the host. Run ps and check that the process list is short. List the proc directory and check that it is mounted. Each test looks at one kernel setting, so a failure points at one flag.
Common failures
An error that says operation not permitted means the namespace or the chroot needs privilege or a kernel setting. An error that says no such file or directory names a missing path, often a shell or a library inside the root. A shell that starts but prints nothing usually lacks the terminal device, because /dev was not populated. Naming the failure before you change the script saves time, and the list above covers most first attempts.