ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 128 - DCA discussion

Report
Export

Can this set of commands identify the published port(s) for a container?

Solution. 'docker port inspect', docker container inspect'

A.

Yes

Answers
A.

Yes

B.

No

Answers
B.

No

Suggested answer: B

Explanation:

The set of commandsdocker port inspectanddocker container inspectwill not identify the published port(s) for a container. The reason is that there is no such command asdocker port inspect.The correct command to inspect the port mappings of a container isdocker port1.The commanddocker container inspectcan also show the port mappings of a container, but it will display a lot of other information as well, so it is not as concise asdocker port2. To identify the published port(s) for a container, you can use either of these commands:

docker port CONTAINERwill list all the port mappings of the container1.

docker port CONTAINER PRIVATE_PORTwill list only the port mapping of the specified private port of the container1.

docker container inspect --format=' { {.NetworkSettings.Ports}}' CONTAINERwill list only the port mappings of the container in a JSON format23.

For example, if you have a container namedwebthat 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?

asked 08/11/2024
Julian Mohabir
32 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first