A Linux administrator is writing a Dockerfile for a custom Nginx image. The container should, by default, start Nginx in the foreground using /usr/sbin/nginx -g 'daemon off;'. Administrators must be able to replace this entire command later simply by appending a different command to docker run, and the chosen command must run as PID 1 rather than through /bin/sh -c. Which single Dockerfile line meets all of these requirements?
The exec-form CMD array (CMD ["/usr/sbin/nginx", "-g", "daemon off;"]) launches the given executable directly, so the process becomes PID 1 and receives signals correctly. Because it is a CMD, any arguments supplied after the image name in docker run completely override the default command, letting operators substitute a different program without using --entrypoint.
The shell-form CMD variant runs through /bin/sh -c, so Nginx would not be PID 1 and signal handling could break. An ENTRYPOINT in exec form makes the command harder to replace (it can only be changed with --entrypoint, not by ordinary arguments). RUN executes at build time, not when the container starts, so it cannot define the runtime command.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
Open an interactive chat with Bash
Why does the process need to run as PID 1 in a container?
Open an interactive chat with Bash
What is the difference between exec-form and shell-form in a Dockerfile?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access