Image showing Docker tip : inspect and grep

Docker tip : inspect and grep

affiliate best offer

Docker inspect and grep

This isn’t so much a docker tip, as it is a jq tip. If you haven’t heard of jq, it is a great tool for parsing JSON from the command line. This also makes it a great tool to see what is happening in a container instead of having to use the –format specifier which I can never remember how to use exactly:

# Get network information:
$ [docker](/blog/en/jenkins/how-to-run-jenkins-jobs-with-docker) inspect 4c45aea49180 | jq '.[].NetworkSettings.Networks'
{
  "bridge": {
    "EndpointID": "ba1b6efba16de99f260e0fa8892fd4685dbe2f79cba37ac0114195e9fad66075",
    "Gateway": "172.17.0.1",
    "IPAddress": "172.17.0.2",
    "IPPrefixLen": 16,
    "IPv6Gateway": "",
    "GlobalIPv6Address": "",
    "GlobalIPv6PrefixLen": 0,
    "MacAddress": "02:42:ac:11:00:02"
  }
}

# Get the arguments with which the [container](/blog/en/docker/3-ways-to-connect-your-dolibarr-container-to-local-database) was started

$ [docker](/blog/en/docker/how-to-setup-your-local-nodejs-development-environment-using-docker) inspect 4c45aea49180 | jq '.[].Args'
[
"-server",
"-advertise",
"192.168.99.100",
"-bootstrap-expect",
"1"
]

# Get all the mounted volumes

11:22 $ [docker](/blog/en/docker/what-is-difference-between-docker-attach-and-exec) inspect 4c45aea49180 | jq '.[].Mounts'
[
{
"Name": "a8125ffdf6c4be1db4464345ba36b0417a18aaa3a025267596e292249ca4391f",
"Source": "/mnt/sda1/var/lib/[docker](/blog/en/docker/how-do-i-connect-mysql-workbench-to-mysql-inside-docker)/volumes/a8125ffdf6c4be1db4464345ba36b0417a18aaa3a025267596e292249ca4391f/_data",
"Destination": "/data",
"Driver": "local",
"Mode": "",
"RW": true
}
]

And of course also works great for querying other kinds of (docker-esque) APIs that produce JSON (e.g Marathon, Mesos, Consul etc.). JQ provides a very extensive API for accessing and processing JSON. More information can be found here: https://stedolan.github.io/jq/

You might also like these blog posts

Full Bright

Full Bright

A professional and sympathic business man.

Contact

Contact Us

Not sure which of these you need? Book the free 20-minute audit — we look at one week of your work and tell you what is worth automating, what is not, and what it would cost. Book it here.

Address

10 rue François 1er,
75008 Paris

When we work

Monday - Friday
9:00AM - 05:00PM