(It was left halfway in the draft of Qiita. It's a mess, so I will update it as appropriate.)
Use --format to retrieve any information you like in docker inspect.
docker inspect --format "\
host:{{.Name}} \
ip: {{.NetworkSettings.IPAddress}} \
gw: {{.NetworkSettings.Gateway}} \
port [host]: {{.NetworkSettings.Ports}}" $(docker ps -q)
host:/container-name \
ip: 172.17.0.2 \
gw: 172.17.0.1 \
port [host]: map[10010/tcp:[] 22/tcp:[{0.0.0.0 12223}] 3000/tcp:[{0.0.0.0 3000}] 80/tcp:[]]
PS C:\Users\name> docker inspect $(docker ps -q) | jq -r '.[].NetworkSettings.Networks.bridge.IPAddress'
172.17.0.3
172.17.0.2
PS C:\Users\name> docker inspect $(docker ps -q) | jq -r '.[].Name, .[].NetworkSettings.Networks.bridge.IPAddress'
/api-test2
/api-test
172.17.0.3
172.17.0.2
PS C:\Users\name> docker inspect $(docker ps -q) | jq -r '.[] | { Name: .Name, IP: .NetworkSettings.Networks.bridge.IPAddress }'
{
"Name": "/api-test2",
"IP": "172.17.0.3"
}
{
"Name": "/api-test",
"IP": "172.17.0.2"
}
PS C:\Users\name> docker inspect $(docker ps -q) | jq '.[] | {moge: {hoge: { Name: .Name, IP: .NetworkSettings.Networks.bridge.IPAddress }}}'
{
"moge": {
"hoge": {
"Name": "/api-test2",
"IP": "172.17.0.3"
}
}
}
{
"moge": {
"hoge": {
"Name": "/api-test",
"IP": "172.17.0.2"
}
}
}
Recommended Posts