DCA practice question 5 of 25

Can this set of commands identify the published port(s) for a container? Solution: docker container inspect', 'docker port'

Full set: 191 questions
Answer options
A: Yes Correct answer
B: No
Correct Answer:
A. Yes
Explanation

Yes, this set of commands can identify the published ports for a container. The docker port command is a direct and concise tool specifically for this purpose; it lists all port mappings in a simple format (e.g., 80/tcp -> 0.0.0.0:8080). The docker container inspect command provides a comprehensive JSON output of the container's configuration and runtime state. Within this output, the NetworkSettings.Ports key contains a detailed object listing all port bindings, including the host IP and port that a container port is mapped to. Both commands effectively provide the required information.

Why Incorrect

B. This is incorrect because both docker port and docker container inspect are valid and standard commands for retrieving a container's port mapping information.

References

1. Docker Documentation, "docker port," Reference > CLI. The official documentation states its purpose is to "List port mappings or a specific mapping for the container."

2. Docker Documentation, "docker container inspect," Reference > CLI. The documentation shows that the command's output includes a NetworkSettings object, which contains a Ports map detailing the host-to-container port bindings.

Scroll to Top