docker inspect
supports Go Templates via the --format
option. This allows for better integration in scripts, without resorting to pipes/sed/grep traditional tools.
Print a container internal IP:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7786807d8084
This is useful for direct network access of load-balancers auto-configuration.
Print a container init PID:
docker inspect --format '{{ .State.Pid }}' 7786807d8084
This is useful for deeper inspection via /proc
or tools like strace
.
Advanced formating:
docker inspect --format 'Container {{ .Name }} listens on {{ .NetworkSettings.IPAddress }}:{{ range $index, $elem := .Config.ExposedPorts }}{{ $index }}{{ end }}' 5765847de886 7786807d8084
Will output:
Container /redis listens on 172.17.0.3:6379/tcp
Container /api listens on 172.17.0.2:4000/tcp