Inspect container details in Docker

Let us learn how to find all of the details about Docker containers, from their current state, to their network settings and configuration.

M Bytes Newsletter
Get the developer newsletter

    Fresh bytes every Thursday. No spam, ever. Unsubscribe anytime.

    Join 9,000+ developers and get three free video lessons every week.

    Working with Docker containers can feel like a black box. Fortunately, there’s a command we can use to find out everything we need to know about them, from their current state, to their network settings and configuration.

    We can use the docker inspect command, passing to it any container name or id:

    docker inspect <container-name or container-id>

    This returns a detailed JSON response which shows everything about your container:

    [
        {
            "Id": "dceb1ccba3f45b1d5ee2f072e5fce7346c7f8f8b6d6898de9741d1173cee7cf6",
            "Created": "2025-01-27T20:03:44.354187367Z",
            "Path": "/docker-entrypoint.sh",
            "Args": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "State": {
                "Status": "running",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 2584009,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2025-02-01T14:20:24.414835086Z",
                "FinishedAt": "2025-01-29T02:17:08.578555733Z"
            },
            ...

    The response can be overwhelming! Thankfully, Docker gives us access to a format flag (-f) to extract just the details we need.

    To use it, we’ll pass in some single quotes, followed by curly brackets. We can then reference properties names with a dot, then their name:

    docker inspect -f '{{.PropertyName}}' container-name

    We can also access nested properties using this simple dot notation.

    Here are a few common examples:

    # Get the container's name
    docker inspect -f '{{.Name}}' container_name
     
    # Check if the container is running
    docker inspect -f '{{.State.Running}}' container_name
     
    # See what image it's using
    docker inspect -f '{{.Config.Image}}' container_name

    Docker also provides us access to some powerful template functions. Rather than using a dot and a reference to the property name, we will reference the name of the function.

    For example, we can list out all environment variables using the range function, coupled along with the println function for line breaks:

    # Print all environment variables
    docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' container_name

    Note that each of these template functions contain their own unique format, but some other functions include:

    • if/else for conditional checks
    • eq for comparing values
    • len for getting array lengths

    Pro tip: Start by running docker inspect without any flags to see the full JSON structure. Once you spot the data you need, use the format flag to extract just that info that you want.