Docker inspect for containers

In this tutorial, How to Docker inspect containers with docker inspect command. It helps to details such as network settings, status, volume, so forth.

Docker inspect container

How to use docker ps command to display containers as below:

$ sudo docker ps

The output 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

How to details for the devopsroles container as below:

$ sudo docker inspect devopsroles

For example, the output devopsroles container as 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 IP Address for the “devopsroles” container as below:

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

The output below:

172.17.0.2

For example, display IP, Image, Name, Host Config, 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

Another method as below:

$ 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

Conclusion

Thought the article, To help you inspect the container expect. For example, How to determine status, volume, networking, so on for containers. The commands useful will be updating this post.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. 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 *

Comment moderation is enabled. Your comment may take some time to appear.

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