2019-02-15 04:59:42 +08:00
# buildah-unshare "1" "June 2018" "buildah"
2018-06-15 03:42:33 +08:00
## NAME
buildah\-unshare - Run a command inside of a modified user namespace.
## SYNOPSIS
2018-06-30 03:39:36 +08:00
**buildah unshare** [*options*] [**--**] [*command*]
2018-06-15 03:42:33 +08:00
## DESCRIPTION
Launches a process (by default, *$SHELL* ) in a new user namespace. The user
namespace is configured so that the invoking user's UID and primary GID appear
to be UID 0 and GID 0, respectively. Any ranges which match that user and
group in /etc/subuid and /etc/subgid are also mapped in as themselves with the
help of the *newuidmap(1)* and *newgidmap(1)* helpers.
2019-02-27 23:29:09 +08:00
buildah unshare is useful for troubleshooting unprivileged operations and for
2018-06-15 03:42:33 +08:00
manually clearing storage and other data related to images and containers.
2022-01-26 04:55:55 +08:00
It is also useful if you want to use the `buildah mount` command. If an unprivileged user wants to mount and work with a container, then they need to execute
2019-02-27 23:29:09 +08:00
buildah unshare. Executing `buildah mount` fails for unprivileged users unless the user is running inside a `buildah unshare` session.
2019-07-16 06:01:51 +08:00
## OPTIONS
2022-03-24 20:03:06 +08:00
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
**--mount**, ** -m** [*VARIABLE=]containerNameOrID*
2019-07-16 06:01:51 +08:00
Mount the *containerNameOrID* container while running *command* , and set the
environment variable *VARIABLE* to the path of the mountpoint. If *VARIABLE*
is not specified, it defaults to *containerNameOrID* , which may not be a valid
name for an environment variable.
2018-06-15 03:42:33 +08:00
## EXAMPLE
buildah unshare id
buildah unshare pwd
2019-02-27 23:29:09 +08:00
buildah unshare cat /proc/self/uid\_map /proc/self/gid\_map
2018-06-15 03:42:33 +08:00
2020-12-18 19:37:59 +08:00
buildah unshare rm -fr $HOME/.local/share/containers/storage /run/user/\`id -u\`/run
2018-06-15 03:42:33 +08:00
2019-07-16 06:01:51 +08:00
buildah unshare --mount containerID sh -c 'cat ${containerID}/etc/os-release'
2025-06-10 22:33:20 +08:00
buildah unshare --mount root=containerID sh -c 'cat ${root}/etc/os-release'
2019-02-27 23:29:09 +08:00
2025-06-10 22:33:20 +08:00
If you want to use buildah with a 'mount' command then you can create a script that looks something like:
```console
cat > buildah-script.sh < < _EOF
#!/bin/bash
2019-02-27 23:29:09 +08:00
ctr=$(buildah from scratch)
mnt=$(buildah mount $ctr)
2025-06-10 22:33:20 +08:00
dnf -y install --installroot=$mnt --use-host-config --setopt "*.countme=false" PACKAGES
2019-02-27 23:29:09 +08:00
dnf -y clean all --installroot=$mnt
buildah config --entrypoint="/bin/PACKAGE" --env "FOO=BAR" $ctr
2020-03-14 05:41:38 +08:00
buildah commit $ctr imagename
2019-02-27 23:29:09 +08:00
buildah unmount $ctr
_EOF
2025-06-10 22:33:20 +08:00
chmod +x buildah-script.sh
2019-02-27 23:29:09 +08:00
```
Then execute it with:
2025-06-10 22:33:20 +08:00
```console
buildah unshare ./buildah-script.sh
2019-02-27 23:29:09 +08:00
```
2018-06-15 03:42:33 +08:00
## SEE ALSO
2019-02-27 23:29:09 +08:00
buildah(1), buildah-mount(1), namespaces(7), newuidmap(1), newgidmap(1), user\_namespaces(7)