How to format output for specific container info?

QuestionsQuestions8 SkillsProDec, 24 2025
0122

To format output for specific container information with docker container inspect, you use the --format flag followed by a Go Template string.

Since the output of inspect is a nested JSON structure, you access fields using a dot notation (e.g., .Parent.Child).

Here are the most common ways to format specific info for your jenkins container:

1. Basic Formatting (Single Field)

If you only want one piece of data, wrap the path in double curly braces:

  • Get the IP address:
    docker container inspect --format '{{ .NetworkSettings.IPAddress }}' jenkins
  • Get the creation date:
    docker container inspect --format '{{ .Created }}' jenkins

2. Formatted Strings (Adding Text)

You can combine fields with your own descriptive text to make it readable:

docker container inspect --format 'Container {{.Name}} was created on {{.Created}}' jenkins

3. Extracting Nested List Data

Some fields, like Ports or Mounts, are arrays or maps. You can use common helper functions:

  • Get all Mount points (Volumes):
    docker container inspect --format '{{ range .Mounts }}{{ .Source }} -> {{ .Destination }}{{ end }}' jenkins

4. Direct JSON Output (Clean JSON)

If you want to extract a specific sub-section as valid JSON (great for scripts or tools like jq):

docker container inspect --format '{{ json .State }}' jenkins

Quick Reference for Common Paths:

  • .State.Status — Running, exited, etc.
  • .Config.Image — The image name used to start it.
  • .LogPath — Location of the container log file on disk.
  • .Name — The container name.
  • .Id — The full container ID.

A small tip: Because you are in a Linux terminal, always wrap your format string in single quotes ('{{ ... }}') so the shell doesn't get confused by the double curly braces!

Which specific piece of information are you trying to find? I can help you write the exact template for it!

0 Comments

no data
Be the first to share your comment!