Sobes.tech
Junior — Middle

How can you obtain information about ports bound to a Docker container?

sobes.tech AI

Answer from AI

To get information about ports bound to a Docker container, you can use the command:

docker port <container_id_or_name>

This command will display a list of the container's mapped ports to the host ports, for example:

80/tcp -> 0.0.0.0:8080
443/tcp -> 0.0.0.0:8443

You can also get more detailed information using:

docker inspect <container_id_or_name>

and look in the output for the NetworkSettings.Ports section, where all forwarded ports and their mappings are listed.

An example of filtering with jq to output only the ports:

docker inspect <container_id_or_name> | jq '.[0].NetworkSettings.Ports'