200-901 Question 119
Single answerYou are reviewing the following Dockerfile for a Python-based application:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . ./
CMD ["python", "app.py"]
What is the purpose of the RUN pip install --no-cache-dir -r requirements.txt instruction in this Dockerfile?
- A
It sets the working directory to
/app. - B
It installs the Python dependencies listed in the
requirements.txtfile. - C
It copies the
requirements.txtfile into the container. - D
It specifies the command to run the application.
Show answer and explanation
Correct answer: B
Explanation
The RUN pip install --no-cache-dir -r requirements.txt instruction in the Dockerfile is used to install the Python dependencies specified in the requirements.txt file. This step ensures that the runtime environment inside the container has all the necessary libraries for the Python application to function correctly. The other instructions in the Dockerfile (e.g., WORKDIR, COPY, and CMD) serve different purposes, such as setting the working directory, copying files, and defining the default command to run the application.
- A. Incorrect.
This option is incorrect because the
WORKDIRinstruction, not theRUNinstruction, sets the working directory to/app. - B. Correct.
This option is correct because the
RUN pip install --no-cache-dir -r requirements.txtinstruction installs the Python dependencies listed in therequirements.txtfile, which is a common step in preparing a Python-based application. - C. Incorrect.
This option is incorrect because the
COPY requirements.txt ./instruction handles copying therequirements.txtfile into the container, not theRUNinstruction. - D. Incorrect.
This option is incorrect because the
CMDinstruction specifies the command to run the application, not theRUNinstruction.