200-901 Question 118
Single answerYou are reviewing a Dockerfile for a new application deployment. The Dockerfile contains the following lines:
FROM python:3.9
COPY app/ /usr/src/app
RUN pip install -r /usr/src/app/requirements.txt
ENTRYPOINT ["python", "/usr/src/app/main.py"]
What will happen when an image built from this Dockerfile is run?
- A
The application will fail to start because the COPY instruction is incorrectly formatted.
- B
The container will execute the Python script located at /usr/src/app/main.py.
- C
The pip install command will run every time the container is started.
- D
The container will fail to run because the ENTRYPOINT instruction is missing an executable flag.
Show answer and explanation
Correct answer: B
Explanation
The Dockerfile defines a base image, copies application files into the image, installs dependencies using pip, and specifies the entry point for the container. The ENTRYPOINT instruction ensures that the Python script '/usr/src/app/main.py' is executed when the container starts. None of the other options correctly describe the behavior defined by this Dockerfile.
- A. Incorrect.
The COPY instruction is correctly formatted. It copies the contents of the 'app/' directory into the '/usr/src/app' directory within the container.
- B. Correct.
This is correct. The ENTRYPOINT instruction specifies that the Python interpreter should run the script located at '/usr/src/app/main.py' when the container starts.
- C. Incorrect.
This is incorrect. The RUN instruction is executed during the image build process, not every time the container starts. The 'pip install' command will not rerun unless the image is rebuilt.
- D. Incorrect.
This is incorrect. The ENTRYPOINT instruction does not require an executable flag. It specifies the command and parameters to execute as the container's main process.