CompTIA Linux+ (XK0-006)Services and User ManagementMedium
A system administrator is preparing to deploy a new Docker container that needs to run a custom Python script as its primary process. The script `app.py` is located in the container's `/app` directory. Which `Dockerfile` instruction should be used to ensure this script is executed when the container starts, allowing arguments to be easily passed to `app.py`?
- ARUN ["python", "/app/app.py"]
- BEXEC ["python", "/app/app.py"]
- CENTRYPOINT ["python", "/app/app.py"]
- DCMD ["python", "/app/app.py"]
Show answer & explanationAnswer & explanation
Correct answer: C. ENTRYPOINT ["python", "/app/app.py"]
The `ENTRYPOINT` instruction in a `Dockerfile` defines the executable that will always run when a container starts. When used in `exec` form with `CMD`, it allows `CMD` (or command-line arguments) to be appended as arguments to the `ENTRYPOINT` command, which is ideal for passing arguments to `app.py`.
Why the other options are wrong
- A. `RUN` executes commands during the image build process, not when the container starts.
- B. `EXEC` is not a valid `Dockerfile` instruction.
- D. `CMD` alone defines the default command. If the user specifies arguments on the `docker run` command line, the `CMD` instruction is entirely overridden, not appended to.
Dockerfile ENTRYPOINT
Configures a container that will run as an executable. Arguments provided to `docker run` will be appended after the `ENTRYPOINT`.
- Defines the main command to execute when a container starts.
- Best used in `exec` form (JSON array).
- Often combined with `CMD` to provide default arguments.
Memory trick: ENTRYPOINT is the main door, CMD is the welcome mat.