Created
March 31, 2019 11:51
-
-
Save bencord0/5535040ae834a4af95d3c11ebee0d065 to your computer and use it in GitHub Desktop.
NSEnter into a docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONTAINER_NAME="$1" | |
exec nsenter --target $( | |
docker inspect --format "{{.State.Pid}}" $( | |
docker ps -q --filter name="${CONTAINER_NAME}" | |
) | |
) --mount --uts --ipc --net --pid |
note: doesn't work for single-binary containers, e.g. many standalone go binaries are distributed without /bin/sh
.
We should probably check fds against limit per process. Something like.
for p in /proc/[0-9]*; do
fds="$(ls $p/fd | wc -l)"
limit="$(sed -n 's/Max open files/max_open_files/p' /proc/1/limits | awk '{print $2}')"
printf 'Pid: %s fds: %s limit: %s Used: %f\n' "$p" "$fds" "$limit" "$((fds/limit*100))"
done
Maybe track the maximum percentage in a container?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Count file descriptors in all docker containers