Created
October 10, 2022 09:32
-
-
Save nanpuyue/39d528158fe8dcfcf54869b53e21b7c4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
docker() { | |
case "$1" in | |
htop) | |
local container="$2" | |
if [ -z "$container" ]; then | |
echo -e '"docker htop" requires at least 1 argument.\n' | |
echo -e 'Usage:\n\tdocker htop CONTAINER [htop OPTIONS]' | |
return 1 | |
fi | |
shift 2 | |
local pid | |
if pid="$(command docker inspect -f '{{.State.Pid}}' "$container")"; then | |
nsenter -p -t "$pid" unshare --mount-proc htop "$@" | |
fi | |
;; | |
*) | |
command docker "$@" | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment