NAME 名称

podman-unshare - Run a command inside of a modified user namespace
podman-unshare - 在修改后的用户命名空间内运行命令

SYNOPSIS 概要

podman unshare [options] [command]
podman unshare [选项] [命令]

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.
在新的用户命名空间中启动一个进程(默认为 $SHELL)。用户命名空间被配置为使调用用户的 UID 和主 GID 分别显示为 UID 0 和 GID 0。任何与该用户和组匹配的范围在 /etc/subuid/etc/subgid 中也会被映射为它们自己,借助 newuidmap(1) 和 newgidmap(1) 辅助程序。

podman unshare is useful for troubleshooting unprivileged operations and for manually clearing storage and other data related to images and containers.
podman unshare 对于排查非特权操作以及手动清除与镜像和容器相关的存储和其他数据非常有用。

It is also useful to use the podman mount command. If an unprivileged user wants to mount and work with a container, then they need to execute podman unshare. Executing podman mount fails for unprivileged users unless the user is running inside a podman unshare session.
对于使用 podman mount 命令也非常有用。如果非特权用户想要挂载并操作容器,则需要执行 podman unshare。除非用户在 podman unshare 会话中运行,否则非特权用户执行 podman mount 会失败。

The unshare session defines two environment variables:
unshare 会话定义了两个环境变量:

  • CONTAINERS_GRAPHROOT: the path to the persistent container’s data.
    CONTAINERS_GRAPHROOT: 持久容器数据的路径。

  • CONTAINERS_RUNROOT: the path to the volatile container’s data.
    CONTAINERS_RUNROOT: 临时容器数据的路径。

IMPORTANT: This command is not available with the remote Podman client.
重要提示:此命令在远程 Podman 客户端中不可用。

OPTIONS 选项

--help, -h --help,-h ¶

Print usage statement 打印使用说明

--rootless-netns

Join the rootless network namespace used for netavark networking. It can be used to connect to a rootless container via IP address (bridge networking). This is otherwise not possible from the host network namespace.
加入用于 netavark 网络的无根网络命名空间。它可用于通过 IP 地址(桥接网络)连接到无根容器。否则,无法从主机网络命名空间进行此操作。

Exit Codes 退出代码 ¶

The exit code from podman unshare gives information about why the container failed to run or why it exited. When podman unshare commands exit with a non-zero code, the exit codes follow the chroot standard, see below:
podman unshare 的退出代码提供了容器运行失败或退出的原因。当 podman unshare 命令以非零代码退出时,退出代码遵循 chroot 标准,见下文:

125 The error is with podman itself
125 错误出现在 podman 本身

$ podman unshare --foo; echo $?
Error: unknown flag: --foo
125

126 Executing a contained command and the command cannot be invoked
126 执行容器中的命令,但无法调用该命令

$ podman unshare /etc; echo $?
Error: fork/exec /etc: permission denied
126

127 Executing a contained command and the command cannot be found
127 执行包含的命令,但找不到该命令

$ podman unshare foo; echo $?
Error: fork/exec /usr/bin/bogus: no such file or directory
127

Exit code contained command exit code
退出代码包含命令退出代码

$ podman unshare /bin/sh -c 'exit 3'; echo $?
3

EXAMPLE 例子 ¶

Execute specified command in rootless user namespace:
在无根用户命名空间中执行指定的命令:

$ podman unshare id
uid=0(root) gid=0(root) groups=0(root),65534(nobody)

Show user namespace mappings for rootless containers:
显示无根容器的用户命名空间映射:

$ podman unshare cat /proc/self/uid_map /proc/self/gid_map
         0       1000          1
         1      10000      65536
         0       1000          1
         1      10000      65536

Show rootless netns information in user namespace for rootless containers:
在用户命名空间中为无根容器显示无根 netns 信息

$ podman unshare --rootless-netns ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: tap0: <BROADCAST,UP,LOWER_UP> mtu 65520 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether aa:8c:0b:73:98:f6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.100/24 brd 10.0.2.255 scope global tap0
       valid_lft forever preferred_lft forever
    inet6 fd00::a88c:bff:fe73:98f6/64 scope global dynamic mngtmpaddr
       valid_lft 86389sec preferred_lft 14389sec
    inet6 fe80::a88c:bff:fe73:98f6/64 scope link
       valid_lft forever preferred_lft forever

SEE ALSO 参见 ¶

podman(1), podman-mount(1), namespaces(7), newuidmap(1), newgidmap(1), user_namespaces(7)