Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Created October 10, 2022 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanpuyue/39d528158fe8dcfcf54869b53e21b7c4 to your computer and use it in GitHub Desktop.
Save nanpuyue/39d528158fe8dcfcf54869b53e21b7c4 to your computer and use it in GitHub Desktop.
#!/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