程式扎記: [ 常見問題 ] Get docker container name by PID

標籤

2015年6月28日 星期日

[ 常見問題 ] Get docker container name by PID

Source From Here 
Question 
I have list of PID's and i need to get their docker container name going the other direction is easy ... Get PID of docker container by image name: 
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
417af6d7dbfa 52366bfd2985:latest "sh /home/root/scrip 19 minutes ago Up 19 minutes 4444/tcp, 5999/tcp insane_ardinghelli

# docker inspect --format '{{.State.Pid}}' insane_ardinghelli
64998

Any idea how to get the name by PID ? 

How-To 
// -q, --quiet=false Only display numeric IDs
# docker ps -q
417af6d7dbfa
# docker ps -q | xargs docker inspect --format '{{.Name}}'
/insane_ardinghelli

Supplement 
Docker Doc - Using the command line 
"xargs" All-IN-One Tutorial Guide

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!