-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpns.sh
30 lines (23 loc) · 924 Bytes
/
pns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
die() { echo "$*" 1>&2 ; exit 1; }
if [ $# -lt 2 ]; then
die "usage: $(basename $0) [pod/container name] [command]"
fi
_name="$1"
shift
_container_name=""
if podman pod exists "$_name" > /dev/null 2>&1 ; then
_container_name="$(podman pod inspect "${_name}" | jq -r '.InfraContainerID')"
if [ "${_container_name}" = "null" ] || [ -z "${_container_name}" ]; then
die "Could not get infra container for '${_name}'"
fi
elif podman container exists "$_name" > /dev/null 2>&1 ; then
_container_name="$_name"
else
die "No pod or container by the name of '$_name'"
fi
if [ "$(podman container inspect -f '{{.State.Status}}' "${_container_name}")" != "running" ]; then
die "Container '$_container_name' is not running"
fi
_cpid="$(podman container inspect -f '{{.State.Pid}}' "${_container_name}")"
exec nsenter --preserve-credentials --user --cgroup --ipc --uts --net --pid --target ${_cpid} "$@"