350-901 · Question #84
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…
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
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?Exhibit
Options
How the community answered
(36 responses)- A72% (26)
- B14% (5)
- C6% (2)
- D8% (3)
Why each option
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.
The `-p 4000:80` flag in the `docker run` command publishes port 80 from the container to port 4000 on the host machine. This means that to access the application running inside the container (which is listening on port 80), you must connect to the host's IP address (localhost) using the mapped external port, which is 4000.
Port 80 on `localhost` is not mapped to the container's application unless explicitly configured otherwise, and usually host port 80 would require root privileges.
`127.0.0.1` is the loopback address for `localhost`, but port 80 refers to the container's internal port, which is not directly accessible from the host without port mapping.
`0.0.0.0` is 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
Source: https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose
Topics
Community Discussion
No community discussion yet for this question.
