350-901 · Question #7
Refer to the exhibit. Which additional line results in the output of Test 1 upon execution of the docker run -rm devnet 1 command in a Dockerfile with this content? FROM alpine:3.7 RUN apk add…
The correct answer is C. ENTRYPOINT ["/bin/echo", "Test"]. To achieve the output "Test 1" when running docker run -rm devnet 1, the Dockerfile must use ENTRYPOINT ["/bin/echo", "Test"] so that the 1 passed during docker run is appended as an argument to the entrypoint command.
Question
Options
- ACMD ["/bin/echo", "Test"]
- BRUN ["/bin/echo", "Test"]
- CENTRYPOINT ["/bin/echo", "Test"]
- DCMD ["/bin/echo Test"]
How the community answered
(61 responses)- A3% (2)
- B2% (1)
- C93% (57)
- D2% (1)
Why each option
To achieve the output "Test 1" when running `docker run -rm devnet 1`, the Dockerfile must use `ENTRYPOINT ["/bin/echo", "Test"]` so that the `1` passed during `docker run` is appended as an argument to the entrypoint command.
If `CMD ["/bin/echo", "Test"]` is used without an `ENTRYPOINT`, the arguments provided to `docker run` (in this case, `1`) completely override the `CMD` instruction, leading to an attempt to execute `1` which would fail.
The `RUN` instruction executes commands during the Docker image build process, not when the container is run, so it would not define the runtime command for the container.
The `ENTRYPOINT` instruction configures a container to run as an executable, and any command-line arguments passed to `docker run` are appended as arguments to the `ENTRYPOINT` command. Therefore, `ENTRYPOINT ["/bin/echo", "Test"]` combined with `docker run ... 1` results in the execution of `/bin/echo Test 1`, producing the desired output.
`CMD ["/bin/echo Test"]` uses the shell form, which would typically be overridden by `docker run` arguments. Even if not overridden, it would output "Test" only and not accept "1" as a separate argument to echo.
Concept tested: Dockerfile ENTRYPOINT vs CMD
Source: https://docs.docker.com/engine/reference/builder/#entrypoint
Topics
Community Discussion
No community discussion yet for this question.