How to use a filter with the 'docker inspect' command?

0119

You can use the --filter option with the docker inspect command to limit the output based on specific criteria. However, it's important to note that docker inspect itself does not support filtering in the same way that commands like docker ps do. Instead, you can use jq or other command-line tools to parse the JSON output.

Here’s how you can use docker inspect with a filter:

  1. Inspect a container and filter the output using jq:

    First, ensure you have jq installed. Then you can run:

    docker inspect CONTAINER_ID_OR_NAME | jq '.[].State.Status'

    This command will show you the status of the specified container.

  2. Using --format option:

    You can also use the --format option to filter the output directly:

    docker inspect --format='{{.State.Status}}' CONTAINER_ID_OR_NAME

This will return just the status of the specified container without the full JSON output. Replace CONTAINER_ID_OR_NAME with the actual ID or name of the container you want to inspect.

0 Comments

no data
Be the first to share your comment!