350-901 · Question #84
350-901 Question #84: Real Exam Question with Answer & Explanation
The correct answer is A: http://localhost:4000. The docker run -p 4000:80 command maps port 4000 on the host machine to port 80 inside the Docker container, making the container's service accessible from the host's localhost on port 4000.
Question
Refer to the exhibit. The command `docker build --tag=friendlyhello .` is run to build a docker image from the given Dockerfile, requirements.txt, and app.py. Then the command `docker run -p 4000:80 friendlyhello` is executed to run the application. Which URL is entered in the web browser to see the content served by the application?
Options
- Ahttp://localhost:4000
- Bhttp://localhost:80
- Chttp://127.0.0.1:80
- Dhttp://0.0.0.0:80
Explanation
The docker run -p 4000:80 command maps port 4000 on the host machine to port 80 inside the Docker container, making the container's service accessible from the host's localhost on port 4000.
Common mistakes.
- B. Port 80 on
localhostis not mapped to the container's application unless explicitly configured otherwise, and usually host port 80 would require root privileges. - C.
127.0.0.1is the loopback address forlocalhost, but port 80 refers to the container's internal port, which is not directly accessible from the host without port mapping. - D.
0.0.0.0is a wildcard address used within the container to listen on all available network interfaces, but it is not a URL to be entered in a web browser from the host.
Concept tested. Docker port mapping and application access
Reference. https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose
Topics
Community Discussion
No community discussion yet for this question.