buildah-unshare(1)
π buildah-unshare β from the buildah manual π
okay bestie, sit down, hydrate, and let me tell you about the most underrated little glow-up in the whole buildah family: buildah-unshare. she runs a command inside a modified user namespace and honestly? she's iconic for it. π«Ά
β¨ NAME β¨
buildah-unshare β run a command inside of a modified user namespace. that's it, that's the whole job. slay. π
β¨ SYNOPSIS β¨
buildah unshare [options] [--] [command]
β¨ DESCRIPTION β¨
so what she does is launch a process β by default it's $SHELL, no cap β inside a brand new user namespace. π and here's the cute part: the namespace is configured so that the invoking user's UID and primary GID show up as UID 0 and GID 0 respectively. like, you're literally root in there, bestie. main character energy. π
and any ranges that match that user and group over in /etc/subuid and /etc/subgid also get mapped in as themselves, with a lil assist from the newuidmap(1) and newgidmap(1) helpers. teamwork makes the dream work fr fr. π§
now, why do you care? buildah unshare is your girl for troubleshooting unprivileged operations, and for manually clearing storage and other data related to images and containers. very "let me just clean up my room" of her. π
she's also the move if you wanna use the buildah mount command. like β if an unprivileged user wants to mount and work with a container, they need to execute buildah unshare first. periodt. running buildah mount just fails for unprivileged users unless they're already inside a buildah unshare session. no session, no mount. that's the vibe check. π
β¨ OPTIONS β¨
--mount,-m[VARIABLE=]containerNameOrIDβ mounts thecontainerNameOrIDcontainer while your command runs, and sets the environment variableVARIABLEto the path of the mountpoint. if you don't give her aVARIABLE, it defaults tocontainerNameOrIDβ which, heads up, might not actually be a valid name for an environment variable. so like, name it yourself if you're feeling fancy. π
β¨ EXAMPLE β¨
here's the cute stuff, copy-paste away bestie:
buildah unshare id
buildah unshare pwd
buildah unshare cat /proc/self/uid_map /proc/self/gid_map
buildah unshare rm -fr $HOME/.local/share/containers/storage
/run/user/`id -u`/run
buildah unshare --mount containerID sh -c 'cat ${containerID}/etc/os-
release'
buildah unshare --mount root=containerID sh -c 'cat ${root}/etc/os-
release'
and if you wanna use buildah with a mount command, you can create a script that looks something like this:
cat > buildah-script.sh << _EOF
#!/bin/bash
ctr=$(buildah from scratch)
mnt=$(buildah mount $ctr)
dnf -y install --installroot=$mnt --use-host-config --setopt "*.countme=false" PACKAGES
dnf -y clean all --installroot=$mnt
buildah config --entrypoint="/bin/PACKAGE" --env "FOO=BAR" $ctr
buildah commit $ctr imagename
buildah unmount $ctr
_EOF
chmod +x buildah-script.sh
then execute it with:
buildah unshare ./buildah-script.sh
β¨ SEE ALSO β¨
buildah(1), buildah-mount(1), namespaces(7), newuidmap(1), newgidmap(1), user_namespaces(7)
and that's the whole page, bestie!! π go forth and unshare responsibly. this lil number comes to you from the buildah crew, dated June 2018 β yeah she's an elder but she still eats. π bye bb, ily, go mount something. β¨π¦π
π¦ where this page comes from
- centos-stream 10: buildah 2:1.45.0-2.el10 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- centos-stream 9: buildah 2:1.43.2-3.el9 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 43: buildah 2:1.41.5-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 43: buildah 2:1.43.2-1.fc43
- fedora 43: buildah 2:1.43.4-1.fc43
- fedora 43: buildah 2:1.43.5-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 44: buildah 2:1.43.0-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 44: buildah 2:1.43.4-1.fc44
- fedora 44: buildah 2:1.43.5-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms