最後更新: 2019-05-15
介紹
nsenter - namespaces enter
Package: util-linux
Usage
# Specify a target process to get contexts from. (只係 get, 但沒有套用)
-t, --target pid
/proc/pid/ns/mnt the mount namespace /proc/pid/ns/uts the UTS namespace /proc/pid/ns/ipc the IPC namespace /proc/pid/ns/net the network namespace /proc/pid/ns/pid the PID namespace /proc/pid/ns/user the user namespace /proc/pid/root the root directory /proc/pid/cwd the working directory respectively
# Set ns
-m, --mount[=file] # If file is specified, enter the mount namespace specified by file
-u, --uts[=file]
-i, --ipc[=file]
-n, --net[=file]
-p, --pid[=file]
-U, --user[=file]
# 設定進入 ns 後身份
-G, --setgid gid
Set the group ID which will be used in the entered namespace and drop supplementary groups. (default is 0)
-S, --setuid uid
Set the user ID which will be used in the entered namespace. (default is 0)
Example
# lxc, 相當於 lxc-attach
# Get VPS 的 PID
lxc-info -n proxy -p # Output: "PID: 32302"
nsenter -t 32302 -m -u -i -n -p
# docker
PID=$(docker inspect --format {{.State.Pid}} <container_name_or_ID>)
nsenter -t $PID -m -u -i -n -p