I want the docker events output to be more readable. Am on windows 10 pro, and on a powershell I run this command.
docker events --format "{{json .}}"
In a different shell when I create a new container,
docker create mcr.microsoft.com/dotnet/core/sdk:3.1
I get some output in json format in the first shell. And that looks something like this.
{"status":"create","id":"7897095c22919bcdcf39612386bebed63296bc33be250445e6069bf4fe90ce37","from":"mcr.microsoft.com/dotnet/core/sdk:3.1","Type":"container","Action":"create","Actor":{"ID":"7897095c22919bcdcf39612386bebed63296bc33be250445e6069bf4fe90ce37","Attributes":{"image":"mcr.microsoft.com/dotnet/core/sdk:3.1","name":"objective_bhaskara"}},"scope":"local","time":1585135301,"timeNano":1585135301351718800}
My question is, is there a better way to format that? What should I do to the command
docker events --format "{{json .}}"
So that it will be formatted in a more readable way. Is there something to pipe that output so that it may look something like the following. I used some online formatter to get to this.
UPDATE
Its now resolved.
As per @Vijay's answer, I first installed jq. The steps are:
Ran power shell as admin.
Ran the command choco install jq
Opened a new command prompt NOT powershell. Somehow power shell did not work.
Issue a command to listen to docker events.
If the output has to be formatted, use the command. Also append jq as follows. Note the double quotes("). Single quotes(') did not work.
docker events --format "{{json .}}" | jq
- Open another prompt and run the following command. This can be a powershell if you wish.
docker run hello-world
- You should now see formatted json output streaming real time.