nerdexam
Cisco

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.

Application Deployment and Security

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"]

How the community answered

(61 responses)
  • A
    3% (2)
  • B
    2% (1)
  • C
    93% (57)
  • D
    2% (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.

ACMD ["/bin/echo", "Test"]

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.

BRUN ["/bin/echo", "Test"]

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.

CENTRYPOINT ["/bin/echo", "Test"]Correct

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.

DCMD ["/bin/echo Test"]

`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

#Dockerfile#CMD vs ENTRYPOINT#Docker Commands#Containerization

Community Discussion

No community discussion yet for this question.

Full 350-901 Practice