How to inspect Docker container

Introduction

In this tutorial, I’ll guide you on How to inspect docker container to gain detailed insights into containers. Docker inspect is a powerful tool that provides comprehensive information about various aspects of a container, including its network settings, current status, attached volumes, and more. By exploring these details, you’ll have a deeper understanding of your containers’ configurations and runtime characteristics.

This knowledge proves invaluable for troubleshooting, optimization, and gaining a holistic view of your Dockerized applications. Follow along as I demonstrate the versatility of Docker inspect, enabling you to effectively manage and analyze your containers with precision and ease.

What is docker inspect?

Docker inspect ” is a command in Docker that provides a detailed overview of container information. This powerful tool unveils specifics such as network configurations, status, and attached volumes. By leveraging “docker inspect,” users gain valuable insights into container settings and runtime details, essential for troubleshooting and optimizing Dockerized applications. Mastery of this command empowers efficient container management, allowing users to delve into the intricacies of their Docker environments with precision and ease

What is a Docker container?

  • Portable Packages: Docker containers encapsulate applications along with their dependencies, ensuring a consistent and portable environment.
  • Isolation: Containers operate independently, isolated from the host system and other containers, promoting stability and consistency.
  • Comprehensive Inclusion: Each container includes the necessary components—code, runtime, libraries, and tools—creating a self-contained unit ready to execute.
  • Docker Platform: Docker, a widely used containerization platform, facilitates the seamless packaging and deployment of applications.
  • Cross-Environment Consistency: Developers can build a container once and run it consistently across various environments, from local development setups to large-scale production systems.
  • Resource Efficiency: Containers optimize resource utilization, offering agility, scalability, and quick deployment, making them popular in modern software development and deployment practices.

Inspect Docker container

Utilize the “docker ps” command to showcase a list of containers as follows:

$ sudo docker ps

The displayed results below

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
055772699b49 devopsroles/nginx:v2 "nginx" 4 seconds ago Up 2 seconds 0.0.0.0:8080->80/tcp devopsroles

Provide details for the “devopsroles” container as illustrated below:

$ sudo docker inspect devopsroles

As an illustration, the output for the “devopsroles” container is presented below:

The omit
"NetworkSettings": {
 "Bridge": "",
 "SandboxID": "38a0b8ae70f0853cf36b25add2182132c2b31183c3d969f7c2b927f75080288c",
 "HairpinMode": false,
 "LinkLocalIPv6Address": "",
 "LinkLocalIPv6PrefixLen": 0,
 "Ports": {
 "80/tcp": [
 {
 "HostIp": "0.0.0.0",
 "HostPort": "8080"
 }
 ]

},
 "SandboxKey": "/var/run/docker/netns/38a0b8ae70f0",
 "SecondaryIPAddresses": null,
 "SecondaryIPv6Addresses": null,
 "EndpointID": "c0103fac129e8ff88fcb597b6cfd1836ca7ffb50580cbe60dc6e7b39f2de1e24",
 "Gateway": "172.17.0.1",
 "GlobalIPv6Address": "",
 "GlobalIPv6PrefixLen": 0,
 "IPAddress": "172.17.0.2",
 "IPPrefixLen": 16,
 "IPv6Gateway": "",
 "MacAddress": "02:42:ac:11:00:02",
 "Networks": {
 "bridge": {
 "IPAMConfig": null,
 "Links": null,
 "Aliases": null,
 "NetworkID": "42dd4e0f69e1edff2c81b2f311b2a0ed53478f47fdf5371643df9f1bdb150ba5",
 "EndpointID": "c0103fac129e8ff88fcb597b6cfd1836ca7ffb50580cbe60dc6e7b39f2de1e24",
 "Gateway": "172.17.0.1",
 "IPAddr$ sudo docker inspect devopsrolesess": "172.17.0.2",
 "IPPrefixLen": 16,
 "IPv6Gateway": "",
 "GlobalIPv6Address": "",
 "GlobalIPv6PrefixLen": 0,
 "MacAddress": "02:42:ac:11:00:02"
 }
 }

How to display the IP Address for the “devopsroles” container as below:

$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' devopsroles

Below is the presented output:

172.17.0.2

For example, display IP, Image, Name, Host Config, and status for containers as below:

$ sudo docker inspect -f 'Image:[{{ .Config.Image}}] Name:{{.Name}} HostConfig:{{ .HostConfig.Binds}} Status:{{ .State.Status}} IP_Container:{{ .NetworkSettings.IPAddress }} ' 055772699b49 | cat -n

The output below:

1 Image:[devopsroles/nginx:v2] Name:/devopsroles HostConfig:[/home/huupv/project/nginx/devopsroles:/var/www/html/devopsroles:ro] Status:running IP_Container:172.17.0.2

An alternative approach is as follows:

$ sudo docker inspect -f 'Image:[{{ .Config.Image}}] Name:{{.Name}} HostConfig:{{ .HostConfig.Binds}} Status:{{ .State.Status}} IP_Container:{{ .NetworkSettings.IPAddress }} ' $(sudo docker ps -a -q) | cat -n

How to display all containers, including non-running

$ sudo docker ps -a -q

The output below:

055772699b49
How to inspect Docker container

Conclusion

Throughout the article, we guide you on inspecting containers effectively. Learn how to determine crucial container details such as status, volume, and networking. We’ll continually update this post with useful commands for your reference. Thank you for exploring the DevopsRoles page – we appreciate your readership!

,

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.