I created a docker container but cannot seem to parse its properties with docker-cli and its format parameter (which uses Go templates).
Any idea greatly appreciated.
Start a docker container, e.g. go to https://birthday.play-with-docker.com/cli-formating/ and click on the docker command in the Prepare the environment section
Choose a property for parsing, e.g. Ports. Printing it with
docker container ls --format '{{ .Ports }}'should yield0.0.0.0:80->80/tcp.Trying to get the port range part after the colon, split the property at ":" (
docker container ls --format '{{ split .Ports ":" }}') which yields array[0.0.0.0 80->80/tcp]The return type (
docker container ls --format '{{ printf "%T" (split .Ports ":") }}') is[]string.The string array has a length of 2 (
docker container ls --format '{{ len (split .Ports ":") }}') .Accessing index value 0 (
docker container ls --format '{{ index (split .Ports ":") 0 }}') yields0.0.0.0as expected.Accessing index value 1 (
docker container ls --format '{{ index (split .Ports ":") 1 }}') yields failed to execute template: template: :1:2: executing "" at <index (split .Ports ":") 1>: error calling index: reflect: slice index out of range instead of80->80/tcp.