Docker Inspecting a running container Printing specific informations

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any Docker Question?