Skip to content

Instantly share code, notes, and snippets.

@Owen-Liuyuxuan
Created February 15, 2023 02:36
Show Gist options
  • Save Owen-Liuyuxuan/726cb8d13a6019bd42f27b7432d012eb to your computer and use it in GitHub Desktop.
Save Owen-Liuyuxuan/726cb8d13a6019bd42f27b7432d012eb to your computer and use it in GitHub Desktop.
Find container with certain PID.
#!/bin/bash -e
# Prints the name of the container inside which the process with a PID on the host is.
# Usage./FindContainerwithPID <pid>
for container in $(docker ps -q); do
status=`docker top $container | grep $1 | wc -l`
if [ $status == "0" ]; then
echo "NOT"
else
docker ps | grep $container
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment