---
title: "Putting a Magnifying Glass to Docker with Docker Inspect"
description: "Learn all about the docker inspect command and how this command can help you get a view of all the inner workings of your Docker environment."
canonical: "https://adamtheautomator.com/docker-inspect/"
---

# Putting a Magnifying Glass to Docker with Docker Inspect

> Learn all about the docker inspect command and how this command can help you get a view of all the inner workings of your Docker environment.

Source: https://adamtheautomator.com/docker-inspect/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Putting a Magnifying Glass to Docker with Docker Inspect](https://adamtheautomator.com/wp-content/uploads/2021/09/Putting-a-Magnifying-Glass-to-Docker-with-Docker-inspect.jpg)

# Putting a Magnifying Glass to Docker with Docker Inspect

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)14 September 20215 min. read

Categories: [DevOps](/category/devops/)

Tags:[Docker](/tag/docker/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Inspecting Docker Images with Docker Inspect](#inspecting-docker-images-with-docker-inspect)
*   [Getting Detailed Information about Docker Networks](#getting-detailed-information-about-docker-networks)
*   [Understanding Docker’s Go Templates and the Format Parameter](#understanding-dockers-go-templates-and-the-format-parameter)
*   [Finding a Docker Container’s Base Image Name](#finding-a-docker-containers-base-image-name)
*   [Finding a Container’s IP Address, Mac Address, and Port Bindings](#finding-a-containers-ip-address-mac-address-and-port-bindings)
*   [Getting a detailed view of Docker Volume Using Docker Inspect](#getting-a-detailed-view-of-docker-volume-using-docker-inspect)
*   [Conclusion](#conclusion)

If you are looking for a detailed view of all the major components of Docker from [Docker images](https://docs.docker.com/engine/reference/commandline/image/), [containers](https://www.docker.com/resources/what-container), and so on, the docker inspect command is for you.

In this tutorial, you’ll learn how to find become a sleuth to discover detailed information about many Docker components for debugging, troubleshooting, or just your mere curiosity.

Let’s begin!

## **Prerequisites**

If you’d like to follow along step-by-step, ensure you have the following:

*   Docker – This tutorial uses Docker v19.03.11 on [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/).

Related:[How to Install and Use Docker on Ubuntu (In the Real World)](https://adamtheautomator.com/docker-ubuntu/)

*   Any Docker image downloaded and available. This tutorial uses the [latest NGINX Docker image](https://hub.docker.com/_/nginx) available on Docker Hub.
    
*   At least one container running on the [Docker](https://adamtheautomator.com/docker-windows/) host.
    

Related:[Deploying your First Container with Docker for Windows](https://adamtheautomator.com/docker-windows/)

## Inspecting Docker Images with `Docker Inspect`

The `Docker Inspect` can provide information on many different Docker components but let’s first start with one of the most popular components; images. If you’ve downloaded an image, how do you then check for information about that image? Let’s find out.

Assuming you have at least one image on your Docker host, use the `inspect` command to query that image. The command below assumes that you have an image called `nginx` on your host.

```bash
docker image inspect nginx
```

Once executed, the command above returns a slew of information via JSON about that particular image. Some notable attributes are:

1.  The image tag.
2.  The time the image was created.
3.  The hostname of the associated container with Docker image nginx.
4.  The [network ports](https://docs.docker.com/engine/reference/commandline/port/) the container makes available to the outside network.
5.  You will also notice the volume(s) attached to the container that belongs to the Docker image nginx.

![Getting a detailed view of Docker image using Docker inspect command.](https://adamtheautomator.com/wp-content/uploads/2021/09/image-79.png)

Getting a detailed view of Docker image using `Docker inspect` command.

## Getting Detailed Information about Docker Networks

The `docker inspect` command isn’t just relegated to grabbing information about images and containers; it can also query networks. Docker networks allow containers to communicate in different ways, such as through a [bridge network](https://docs.docker.com/network/bridge/) (a private network), a [host network](https://docs.docker.com/network/host/) (a public network), or an [overlay network](https://docs.docker.com/network/overlay/).

Knowing Docker networks is important as it allows you to switch to another Docker network anytime as per the need of the application by [disconnecting](https://docs.docker.com/engine/reference/commandline/network_disconnect/) and then [connecting](https://docs.docker.com/engine/reference/commandline/network_connect/) back.

Assuming you are still on the terminal:

1\. Run the command below. The `docker network ls` command lists all the networks present in the Docker. You’ll need the output of this command to find the network’s ID.

```bash
docker network ls
```

![Listing the Docker network](https://adamtheautomator.com/wp-content/uploads/2021/09/image-80.png)

Listing the Docker network

Next, pass a network ID to the `docker inspect network` command. This command returns various information about the particular network, as shown below.

```yaml
docker inspect network 4748f122c987
```

1\. The type of network.

2\. The subnet address the network uses.

3 and 4. Summary information about every container that’s using this particular network.

![](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/519b4f92-ca46-4694-81d6-f77b96bb1d67/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20210913%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210913T094132Z&X-Amz-Expires=86400&X-Amz-Signature=e241f3f3e3d4a69a7f9d03a69cd866ad42cc9a9af106b9c11eb6509334d606e4&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22Untitled.png%22)

Inspecting the Docker network

## Understanding Docker’s Go Templates and the `Format` Parameter

Up to now, you have learned how to use Docker inspect command without using any additional [options](https://docs.docker.com/engine/reference/commandline/inspect/#options) parameters. But if you need to manipulate the output format, consider using the `--format` flag. The `--format` parameter uses [Go templates](https://pkg.go.dev/text/template#example-Template) to filter and display the information returned from `docker inspect`.

Various functions are used along with the format flag, such as [join](https://docs.docker.com/config/formatting/#join), [println](https://docs.docker.com/config/formatting/#join), [table](https://docs.docker.com/config/formatting/#table), etc. Let’s discuss a few of them!

For example, maybe you want to join some values together from the output from a particular container. If so, the `join` command works well. Below, you’ll see that the `join` command concatenates strings together (`nginx, -g, daemon off`) with each element separated by a separator (`,`).

```bash
docker inspect --format '{{join .Args " , "}}' container_id
```

![](https://adamtheautomator.com/wp-content/uploads/2021/09/image-81-1024x44.png)

Demonstrating the join format function for Docker Inspect.

Maybe you’d like to capitalize a value? Use the `upper` command.

```bash
docker inspect --format "{{upper .Name}}" container_id
```

![](https://adamtheautomator.com/wp-content/uploads/2021/09/image-82-1024x44.png)

Demonstrating the upper command format function for Docker Inspect.

You can find many [different examples of using the `format` parameter](https://docs.docker.com/config/formatting/).

## Finding a Docker Container’s Base Image Name

In the previous section, you saw how to get a detailed view of all your Docker images, including the containers using those images. But what if you already know a container ID and need to find the image that it was created from quickly? You can provide the container ID to `docker inspect`.

To find the name of the image that a particular container is built from, run the below `docker inspect` command. The below command passes the container ID (`8f34d039fa3a` in this case) to `docker inspect` and uses the `format` parameter to only return the `image` value from the `Config` node in the JSON output.

```bash
# 8f34d039fa3a is the container represented with ContainerID.
docker inspect --format='{{.Config.Image}}' 8f34d039fa3a
```

![Docker inspect command that shows nginx image](https://adamtheautomator.com/wp-content/uploads/2021/09/image-83.png)

Docker inspect command that shows `nginx` image

You can see what the entire `Config` node looks like below and where the `Image` name comes from.

![Finding the name of the Image used by Contai](https://adamtheautomator.com/wp-content/uploads/2021/09/image-84.png)

Finding the name of the Image used by Container

## Finding a Container’s IP Address, Mac Address, and Port Bindings

Although you now know how to find the network a container uses, how do you know what IP address or Mac Address, and Port Bindings on that network a container uses? You guessed it! `docker inspect`.

To narrow down the IP address that a container uses, pass the container ID to the `docker inspect` command. Again, use the `format` parameter to filter out the unwanted JSON to get down to exactly what you’re looking for.

You’ll see the `format` parameter argument below tells `docker inspect` only to return the value embedded inside the `NetworkSettings`→`Networks`→ `IPAddress` JSON attribute using the `range` attribute. Range attribute allows you to iterate over an array, setting the`.` value to each array element.

```bash
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my_container
```

![Finding the IP address using Docker inspect command.](https://adamtheautomator.com/wp-content/uploads/2021/09/image-85.png)

Finding the IP address using Docker inspect command.

You’ll see the main `NetworkSettings` node below and where the `IPAddress` value is nested.

![](https://adamtheautomator.com/wp-content/uploads/2021/09/image-86.png)

Inspecting the NetworkSettings values from Docker Inspect.

Similarly, to find the **MAC address** of the container, use `docker inspect` container command as shown below.

Again, You’ll see that the `format` parameter argument below uses the `range` attribute but this time, find the container’s Mac address by checking in `NetworkSettings`→`Networks`→ `Mac address`.

```bash
docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' 3dd206041249
```

![Retrieving the Mac address of the Docker Container.](https://adamtheautomator.com/wp-content/uploads/2021/09/image-87.png)

Retrieving the Mac address of the Docker Container.

Finally, To check all **port bindings of a container,** run the below `docker inspect` command. You’ll see the `format` parameter argument below uses the `range` attribute to find the container’s port bindings by checking in `NetworkSettings`→`HostPort`.

> O_ne should know about the port bindings because if any port is already used, it shouldn’t be used again; otherwise, it will throw an error message stating the port is already allocated._

```bash
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' 8f34d039fa3a
```

![Checking the Port Binding of the container.](https://adamtheautomator.com/wp-content/uploads/2021/09/image-88.png)

Checking the Port Binding of the container.

## Getting a detailed view of Docker Volume Using `Docker Inspect`

Up to now, you have learned how to find detailed information about the images, containers, and networking, but you haven’t learned about storage. Let’s change that.

To ensure the tutorial has at least one mounted volume attached to a container, let’s first create a container and mount a storage volume.

> _If you already have a storage volume mounted to a container, you can skip this part._

The command below creates a new Docker container called `my_container`, exposes port 80 to the host (`-p 80:80`), mounts a volume based on the host’s _/var/container\_dir_ directory called _mounted\_val_ (`-v mounted_vol:/var/container_dir`) using the `nginx` image.

```bash
docker run --name my_container -p 80:80 -v mounted_vol:/var/container_dir nginx
```

Now that you have a volume mounted to a container provide the volume’s name to `docker volume inspect`. Notice below that the command returns JSON output, only providing information about the mounted storage volume.

```bash
docker volume inspect mounted_vol
```

![Inspecting the docker volume](https://adamtheautomator.com/wp-content/uploads/2021/09/image-89.png)

Inspecting the `docker volume`

## Conclusion

You should now be able to use the `docker inspect` command in many different situations, from querying information about images, containers, networking, and storage.

How do you plan to use `docker inspect` to query information about your own Docker environment?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fdocker-inspect%2F&text=Putting%20a%20Magnifying%20Glass%20to%20Docker%20with%20Docker%20Inspect)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fdocker-inspect%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fdocker-inspect%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-13.webp)

### [Azure Container Apps: Instant Preview Environments per PR](/build-ephemeral-preview-environments-every-pr/)

Build isolated preview environments for every pull request using Azure Container Apps revision labels and Azure DevOps pipelines with scale-to-zero economics.

![](https://adamtheautomator.com/wp-content/uploads/2025/11/55418e927e511ae263219c072e27d637c2a967a5036de7020b329582db775c26.png)

### [Automating Docker Container Health Checks with Python and Local Notifications](/docker-health-checks-python/)

Docker's built-in health checks are passive—they tell Docker when a container fails, but do they tell you? In this tutorial, we'll build a lightweight Python monitoring system that runs entirely on your infrastructure with zero external dependencies. You'll learn to detect container failures in real-time, send instant alerts, and maintain a complete audit log of every state change.

![](https://adamtheautomator.com/wp-content/uploads/2023/07/gitea-docker.jpg)

### [Gitea Docker: Your Ultimate Self-Hosted Git Solution](/gitea-docker/)

Learn how to install a Gitea Docker instance and self-host Git repositories securely in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
