200-901 · Question #259
Refer to the exhibit. Which command, including arguments, is executed when the container starts?
The correct answer is A. /bin/sh -c "/bin/sleep 30 && nginx -g 'daemon off;'". The container's startup command is assembled from the Dockerfile ENTRYPOINT and CMD instructions, resulting in /bin/sh -c executing a 30-second sleep followed by nginx.
Question
Refer to the exhibit. Which command, including arguments, is executed when the container starts?
Exhibit
Options
- A/bin/sh -c "/bin/sleep 30 && nginx -g 'daemon off;'"
- B/bin/sh -c "/bin/sleep 10 && nginx -g 'daemon off;'"
- C/bin/bash -c "/bin/sleep 30 && nginx -g 'daemon off;'"
- D/bin/sh -c "/bin/sleep 30" && nginx -g 'daemon off;'
How the community answered
(59 responses)- A86% (51)
- B3% (2)
- C8% (5)
- D2% (1)
Why each option
The container's startup command is assembled from the Dockerfile ENTRYPOINT and CMD instructions, resulting in /bin/sh -c executing a 30-second sleep followed by nginx.
In Docker, when ENTRYPOINT is defined as ['/bin/sh', '-c'] and CMD provides the shell command string, the runtime concatenates them so the container executes /bin/sh -c followed by that string at startup. The exhibit specifies a 30-second sleep value and the nginx daemon command, making /bin/sh -c "/bin/sleep 30 && nginx -g 'daemon off;'" the correct complete command executed when the container starts.
The sleep duration specified in the Dockerfile exhibit is 30 seconds, not 10; selecting 10 contradicts the value defined in the CMD or ENTRYPOINT instruction.
The shell interpreter defined in the exhibit is /bin/sh, not /bin/bash; /bin/bash would only be used if explicitly specified in the ENTRYPOINT instruction.
This syntax incorrectly splits the command, running /bin/sh -c "/bin/sleep 30" as one process and nginx as a separate shell invocation, which does not reflect how Docker merges ENTRYPOINT and CMD into a single command.
Concept tested: Docker ENTRYPOINT and CMD container startup command assembly
Source: https://docs.docker.com/reference/dockerfile/#cmd
Topics
Community Discussion
No community discussion yet for this question.
