350-901 · Question #7
350-901 Question #7: Real Exam Question with Answer & Explanation
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
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 --no-cache bash
Options
- ACMD ["/bin/echo", "Test"]
- BRUN ["/bin/echo", "Test"]
- CENTRYPOINT ["/bin/echo", "Test"]
- DCMD ["/bin/echo Test"]
Explanation
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.
Common mistakes.
- A. If
CMD ["/bin/echo", "Test"]is used without anENTRYPOINT, the arguments provided todocker run(in this case,1) completely override theCMDinstruction, leading to an attempt to execute1which would fail. - B. The
RUNinstruction 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. - D.
CMD ["/bin/echo Test"]uses the shell form, which would typically be overridden bydocker runarguments. 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
Reference. https://docs.docker.com/engine/reference/builder/#entrypoint
Topics
Community Discussion
No community discussion yet for this question.