docker:tldr:f23be
The command docker inspect --format='${range $p, $conf := -NetworkSettings-Ports} ${$p} -> ${(index $conf 0)-HostPort} ${end}' ${container}
is used to inspect the network settings and ports of a Docker container.
Here's a breakdown of the command:
-
docker inspect
: This command is used to obtain detailed information about a Docker container. -
--format='${range $p, $conf := -NetworkSettings-Ports} ${$p} -> ${(index $conf 0)-HostPort} ${end}'
: This option allows you to specify a Go template to format the output ofdocker inspect
command. In this case, the template is provided in single quotes ('
) and is using Go templating syntax. -
${range $p, $conf := -NetworkSettings-Ports}
: This part of the template initializes a range loop to iterate over each port mapping in the "NetworkSettings-Ports" section of the inspected container's Docker JSON output. The variable$p
represents the port number, and$conf
represents the port configuration. -
${$p} -> ${(index $conf 0)-HostPort}
: This part of the template is the output format for each port. It uses the port number ($p
) and theHostPort
value from the port configuration ($conf
). Theindex
function is used to access the first element of the$conf
array, which contains the port configuration. -
${end}
: This indicates the end of the range loop. -
${container}
: This is the placeholder for the container ID or name that you want to inspect. It is passed as an argument to thedocker inspect
command.
Overall, this command will output a formatted list of the container's ports and their corresponding host ports.