Correct Answer: B
The set of commands docker port inspect and docker container inspect will not identify the published port(s) for a container. The reason is that there is no such command as docker port inspect. The correct command to inspect the port mappings of a container is docker port1. The command docker container inspect can also show the port mappings of a container, but it will display a lot of other information as well, so it isnot as concise as docker port2. To identify the published port(s) for a container, you can use either of these commands:
docker port CONTAINER will list all the port mappings of the container1.
docker port CONTAINER PRIVATE_PORT will list only the port mapping of the specified private port of the container1.
docker container inspect --format=' { {.NetworkSettings.Ports}}' CONTAINER will list only the port mappings of the container in a JSON format23.
For example, if you have a container named web that publishes port 80 to port 8080 on the host, you can use any of these commands to identify the published port:
$ docker port web
80/tcp -> 0.0.0.0:8080
$ docker port web 80
0.0.0.0:8080
$ docker container inspect --format=' { {.NetworkSettings.Ports}}'web
map[80/tcp:[map[HostIp:0.0.0.0 HostPort:8080]]]
:
docker port
docker container inspect
How can I grab exposed port from inspecting docker container?