Format the output of "docker ps" or "docker container ls" using the slice function in go template

Good question…

I don’t understand why those two are not producing the same result:

docker container ls --filter "ancestor=php:8.0-apache" --format '{{ $i:="php:8.0-apache"}}{{slice $i 0 12}}'
docker container ls --filter "ancestor=php:8.0-apache" --format '{{ $i:=(printf "%s" .Image)}}{{slice $i 0 12}}'

While the first variation works, the second does not. Even though I would expect printf "%s" .Image to create a new string, identical to the static string, but it is treated differently.

I hope you find the root cause, or at least a statisfying understanding what causes it :slight_smile: