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

沒有留言:

張貼留言

[Linux 文章收集] Centos7 的 ifconfig 和 netstat

Source From  Here   Preface   Centos7/RHEL 7 的  ifconfig ,  netstat ,  route  和  traceroute  都不見了,其實 Centos6 就已經有一些變革,只是  netstat  和  ifco...