DCA · Question #115
You want to create a container that is reachable from its host's network. Does this action accomplish this? Solution: Use either EXPOSE or --publish to access the containers on the bridge network
The correct answer is A. Yes. Using --publish (or -p) explicitly maps container ports to host ports, making the container reachable from the host's network, while EXPOSE merely documents the ports.
Question
You want to create a container that is reachable from its host's network. Does this action accomplish this? Solution: Use either EXPOSE or --publish to access the containers on the bridge network
Options
- AYes
- BNo
How the community answered
(40 responses)- A85% (34)
- B15% (6)
Why each option
Using `--publish` (or `-p`) explicitly maps container ports to host ports, making the container reachable from the host's network, while `EXPOSE` merely documents the ports.
The `--publish` (or short form `-p`) option maps a container port to a host port, making the container's service accessible from the host's network interfaces. While `EXPOSE` only declares the port, `--publish` actually opens it on the host, fulfilling the requirement for host reachability.
The `--publish` option specifically enables host-to-container port mapping, making the container accessible from the host network.
Concept tested: Docker container port publishing
Source: https://docs.docker.com/engine/reference/run/#publish-or-expose-port-s
Topics
Community Discussion
No community discussion yet for this question.