> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Inspect and Logs

> Guides using docker inspect and docker logs to view container metadata, status, networking, mounts, and stdout/stderr, including --format, jq examples and troubleshooting tips.

Use `docker ps` to list running containers (names and IDs). When you need deeper information about a container’s state, mounts, configuration, or networking, use `docker inspect` with the container name or ID. `docker inspect` returns detailed metadata in JSON format.

<Callout icon="lightbulb" color="#1CB2FE">
  `docker inspect` always returns a JSON array (even for a single container). To extract specific fields or to pretty-print the output, use tools like `jq` or Docker’s `--format` option with Go templates.
</Callout>

## Inspect: get container metadata

Basic inspect command:

```bash theme={null}
docker inspect <container-name-or-id>
```

Example: inspect a container named `blissful_hopper`

```bash theme={null}
docker inspect blissful_hopper
```

Sample (truncated) JSON output:

```json theme={null}
[
  {
    "Id": "35505f7810d17291261a43391d4b6c0846594d415c...",
    "Name": "/blissful_hopper",
    "Path": "python",
    "Args": ["app.py"],
    "State": {
      "Status": "running",
      "Running": true
    },
    "Mounts": [],
    "Config": {
      "Entrypoint": ["python", "app.py"]
    },
    "NetworkSettings": { /* ... */ }
  }
]
```

### Extract specific fields with `--format`

If you need a single field (for example the container status or IP), use `--format` with Go templates to avoid parsing the full JSON:

```bash theme={null}
# Get the container's status
docker inspect --format='{{.State.Status}}' blissful_hopper

# Get the container's IP address (for default bridge or user-defined networks)
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' blissful_hopper
```

In documentation or automation, wrap Go templates and examples in code formatting to avoid rendering issues, e.g. `{{.State.Status}}`.

## Quick command reference

| Command | Purpose | Example |
| - | - | - |
| `docker ps` | List running containers (name, ID, image, status) | `docker ps -a` |
| `docker inspect` | Show detailed JSON metadata for a container | `docker inspect blissful_hopper` |
| `docker inspect --format` | Extract a specific field using Go templates | `docker inspect --format='{{.State.Status}}' blissful_hopper` |
| `jq` | Filter/format JSON output from `docker inspect` | `docker inspect blissful_hopper \| jq '.[0].Config'` |

## Logs: view container stdout/stderr

Docker captures a container’s stdout and stderr and exposes it via `docker logs` (works for running and exited containers). Note that logs are available only through the configured logging driver — some drivers may forward logs to external systems and not keep them locally.

<Callout icon="warning" color="#FF6B6B">
  Some logging drivers (or custom logging configurations) send logs to external services and may not make them available via `docker logs`. Verify the container’s `LogConfig` (via `docker inspect`) if you can’t retrieve logs with `docker logs`.
</Callout>

Basic usage:

```bash theme={null}
# View all logs
docker logs blissful_hopper

# Follow logs (like tail -f)
docker logs -f blissful_hopper

# Tail only the last N lines
docker logs --tail 100 blissful_hopper

# Follow logs and show timestamps
docker logs -f --timestamps blissful_hopper
```

Example of typical log output (application messages):

```text theme={null}
2026-10-07T12:00:00.000000000Z Starting web server on port 8080
2026-10-07T12:00:02.123456789Z Received request: GET /health
2026-10-07T12:00:02.123567890Z Response: 200 OK
```

Tips for troubleshooting and analysis:

* Use `-f` to stream logs in real time while debugging.
* Combine `--tail` with `-f` to limit initial output for large logs.
* Pipe logs to standard Unix tools: `docker logs CONTAINER | grep ERROR`, or to `jq` when logs are JSON: `docker logs CONTAINER | jq '.'`.
* Inspect `LogConfig` in `docker inspect` to confirm where logs are being sent.

## Examples: combine inspect + logs

1. Confirm container status before viewing logs:

```bash theme={null}
docker inspect --format='{{.State.Status}}' blissful_hopper
docker logs -f blissful_hopper
```

2. Get container IP and then check application logs:

```bash theme={null}
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' blissful_hopper
docker logs --tail 200 blissful_hopper
```

## Links and references

* [Docker CLI: ps](https://docs.docker.com/engine/reference/commandline/ps/)
* [Docker CLI: inspect](https://docs.docker.com/engine/reference/commandline/inspect/)
* [Docker CLI: logs](https://docs.docker.com/engine/reference/commandline/logs/)
* [jq — lightweight and flexible command-line JSON processor](https://stedolan.github.io/jq/)
* Go templates in Docker `--format` (see `docker inspect --help`)

That's all for this article.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/docker-training-course-for-the-absolute-beginner/module/7a88081c-a9d0-45cc-b75e-55c93b6886d6/lesson/73d180f9-ca4e-4bf3-a5b2-f4cb73c5956c" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/docker-training-course-for-the-absolute-beginner/module/7a88081c-a9d0-45cc-b75e-55c93b6886d6/lesson/b7b914c5-7331-4239-951b-e0814fcada09" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.