Trusted answers to developer questions

What is Docker inspect?

docker inspect is a command that returns detailed, low-level information on Docker objects. Those objects can be docker images, containers, networks, volumes, plugins, etc.

Syntax

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

  • OPTIONS
    • --format: Format the output using the given Go template
    • --size: Display total file sizes if the type is container
    • --type: Return JSON for specified type

By default, docker inspect returns information in JSON format.

Examples

  1. Get an instance’s IP address:
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_NAME
  1. Get multiple instances’ image name:
docker inspect --format='{{.Config.Image}}' $INSTANCE1_ID $INSTANCE2_ID
  1. List all port bindings:
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_NAME

RELATED TAGS

docker
docker command
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?