Deploying the required system for a quick debugging
Sometimes you need to quickly test something in a specific environment that is native to that application, such as Ubuntu. And no, it’s not Docker, because you often need to have a normal ability to work with this environment as a system, edit configs, install packages, and so on. Rebuilding docker images or configuring something inside them is a very specific and strange pleasure. KVM is not needed here, LXC takes longer to set up and is more difficult to interact with. Yes, the easiest way is debootstrap and good old chroot.
Let me note that this is not about isolation and security, but about a quick way to run trusted software in a specific environment.
mount -t proc proc /data/.box/amd64_xenial/proc
mount --bind /dev /data/.box/amd64_xenial/dev
mount -t devpts devpts /data/.box/amd64_xenial/dev/pts
mount -t sysfs sysfs /data/.box/amd64_xenial/sys
chroot /data/.box/amd64_xenial
# Add a user, the user's uid and gid must be different from the host's defaults
groupadd --gid 7231 user
adduser --home /home/user --ingroup user --uid 7231 user
dpkg --add-architecture i386
apt-get update
apt-get install software-properties-common
add-apt-repository multiverse
apt-get update
aptitude install locales binutils
dpkg-reconfigure locales
# Access to localhost only
iptables -A OUTPUT -d 127.0.0.1 -m state --state NEW,RELATED,ESTABLISHED -m owner --uid-owner 11000 -j ACCEPT
iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -m owner --uid-owner 11000 -j DROP