📜  带有 ip 的 docker ps - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:56.947000             🧑  作者: Mango

代码示例10
# In order to extract the ip, you can do something like 
docker inspect $CID | grep IPAddress | cut -d '"' -f 4, it works fine :) – 

# Bringing it all together, this shell alias should list all container ids and their ips: 
alias  dockerip='docker ps | tail -n +2 | while read cid b; do echo -n "$cid\t"; docker inspect $cid | grep IPAddress | cut -d \" -f 4; done' – 

# As mentionned by @user3119830, there is a new option to inspect. Now, you can get the Ip easier with 
docker inspect -format '{{ .NetworkSettings.IPAddress }}' ${CID}

# Just a note. The single dash options are being deprecated so that -format will become --format. – 
docker inspect -format '{{ .NetworkSettings.IPAddress }}' ${CID} is the new syntax. -format is deprecated, it becomes --format. –