Featured Video Play Icon

Docker Inspect Container: How-To Guide

Inspecting Docker containers can be an effective troubleshooting technique for developers as it allows you to view the internal state of the container and diagnose issues that may be causing errors. Using Docker inspect container commands, you can view the container’s logs, configuration, environment variables, and other information. This give you valuable insights into the container’s behavior and helps to identify potential problem areas. With this information, you can quickly pinpoint and resolve issues, resulting in more efficient troubleshooting and faster problem resolution.

Lead Developer Career Guide Banner 01

Using VSCode

In VSCode, you can right-click a running container and select inspect.

Docker Inspect Container in VSCode
Docker Inspect Container in VSCode

I won’t review all of the values shown here but I wanted to highlight the most useful information.

Docker Inspect Container JSON Results
Docker Inspect Container JSON Results
  • ID is the container id.
  • State includes various status flags and the process id for the container which we will talk about in detail later in this course.
  • Image is the image this container is running.
  • You can also find the system path to the container’s log file in the LogPath ouput. This is what you would use to ship logs to a central location and enable log rotation to save disk space.
  • Name is the user defined name for the container.
  • RestartCount shows the number of times the container has been restarted. This value is the key value used when defining a container’s restart policy.
  • Volumes displays the volume mapping between the host system and the container.
  • NetworkSettings lists the network environment for the container and the applications within the image.
  • HostConfig includes configurations for how the container will interact with the host system. This information is crucial to help you manage CPU and memory limits, networking values, or device driver paths.
  • And finally, Config shows the runtime configuration options set when the docker run command was executed.

Docker Inspect Command

You can also use the docker inspect command to return specific sections.

docker inspect --format='{{.Config.Image}}' [container name]

The format option allows you to enter a search string within single quotes and then double curly brackets or braces. You can get an instance’s image name by searching for .Config.Image. And then you put in the container name.

And you can get the Id using the string syntax .Id.

docker inspect --format='{{.Id}}'

Another useful string to search for is .LogPath which will return the path to the log file for a container.

docker inspect --format='{{.LogPath}}' [container name]

To view the config section, you would search for .config. I’m also going to add json so that the output is formatted.

Then you can copy the output, create a new file and specify the JSON format. Right-click anywhere in the new file and select format document.

docker inspect --format='{{json .Config}}' [container name]

If you go back to the full output from earlier, you can search for config and see the same results. You can set the format option to the name of any parent field to return the structure beneath it.

Docker Inspect Container JSON Results Config Section
Docker Inspect Container JSON Results Config Section

Docker Inspect Container – Online Course

Tactics and Tools for Troubleshooting Docker on Pluralsight
Tactics and Tools for Troubleshooting Docker – Online Course Available on Pluralsight

If you’re struggling with Docker errors, check out my Pluralsight course, Tactics and Tools for Troubleshooting Docker. This course provides developers with the skills they need to troubleshoot and fix the most common Docker errors. By the end of this course, you will have the skills you need to reduce the time it takes you to assess and fix issues. Click the link below to get started with a free trial today!

Categories: DevOps, DockerTags: