‹ All Docker Interview Questions questions

Docker Interview Question 2: Entrypoint Cmd Arguments

Docker Interview Questions · Test 1 · question 2 of 10

Dockerfile Instructionsmedium

An image is built from a Dockerfile that ends with these two instructions:

ENTRYPOINT ["python", "app.py"] and CMD ["--port", "8000"]

An engineer starts a container with docker run myapp --debug. Which command does the container actually run as its main process?

Select one answer
Show answer and explanation

Answer:

  • D. python app.py --debug

With an exec-form ENTRYPOINT, CMD supplies only default arguments. Arguments given after the image name in docker run <image> ... are appended after all elements of the exec-form ENTRYPOINT and override all elements of `CMD`. So --port 8000 is dropped and --debug is passed instead, giving python app.py --debug. This ENTRYPOINT + CMD pattern is how you ship a fixed executable with overridable default flags.

Option A assumes the run arguments are added on top of CMD; they replace it, they do not extend it.

Option B describes what would happen with no ENTRYPOINT (the arguments replace CMD). Replacing an ENTRYPOINT requires the explicit docker run --entrypoint flag.

Option C describes the shell form of ENTRYPOINT, which ignores CMD and command-line arguments. The stem uses the exec (JSON array) form.

Reference: Dockerfile reference - ENTRYPOINT

Practice Test 1 ›

Study guides for Docker Interview Questions