as @mcuenez told as a comment. His proposal is in my opinion better that that from @Mickael B. since it is more generic and you don't have to write a very long command go get all the data.
docker ps --all --no-trunc --format='{{json .}}'
and to formant the output you could use jq
.
docker ps --all --no-trunc --format="{{json . }}" | jq --tab .
The output would be something like this
{
"Command": "zsh",
"CreatedAt": "2023-02-22 23:40:37 +0100 CET",
"ID": "b2163d5d7229",
"Image": "local-image-with-zsh",
"Labels": "org.opencontainers.image.ref.name=ubuntu,org.opencontainers.image.version=22.04",
"LocalVolumes": "0",
"Mounts": "",
"Names": "nervous_einstein",
"Networks": "bridge",
"Ports": "",
"RunningFor": "14 minutes ago",
"Size": "215kB (virtual 1.22GB)",
"State": "running",
"Status": "Up 14 minutes"
}
{
"Command": "bash",
"CreatedAt": "2023-02-22 23:39:22 +0100 CET",
"ID": "1281e43c27a4",
"Image": "ghcr.io/example-user/remote-image-with-bash",
"Labels": "org.opencontainers.image.ref.name=ubuntu,org.opencontainers.image.version=22.04",
"LocalVolumes": "0",
"Mounts": "",
"Names": "hardcore_cerf",
"Networks": "bridge",
"Ports": "",
"RunningFor": "15 minutes ago",
"Size": "216kB (virtual 1.22GB)",
"State": "running",
"Status": "Up 15 minutes"
}
With jq
you can even create a valid json out of the single entries with a -s
flag.
[
{
"Command": "zsh",
"CreatedAt": "2023-02-22 23:40:37 +0100 CET",
"ID": "b2163d5d7229",
"Image": "local-image-with-zsh",
"Labels": "org.opencontainers.image.ref.name=ubuntu,org.opencontainers.image.version=22.04",
"LocalVolumes": "0",
"Mounts": "",
"Names": "nervous_einstein",
"Networks": "bridge",
"Ports": "",
"RunningFor": "20 minutes ago",
"Size": "215kB (virtual 1.22GB)",
"State": "running",
"Status": "Up 20 minutes"
},
{
"Command": "bash",
"CreatedAt": "2023-02-22 23:39:22 +0100 CET",
"ID": "1281e43c27a4",
"Image": "ghcr.io/example-user/remote-image-with-bash",
"Labels": "org.opencontainers.image.ref.name=ubuntu,org.opencontainers.image.version=22.04",
"LocalVolumes": "0",
"Mounts": "",
"Names": "hardcore_cerf",
"Networks": "bridge",
"Ports": "",
"RunningFor": "21 minutes ago",
"Size": "216kB (virtual 1.22GB)",
"State": "running",
"Status": "Up 21 minutes"
}
]