Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to specify the base image in a Dockerfile.
ML Python
FROM [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RUN or COPY instead of FROM as the first instruction.
Specifying commands instead of an image name.
✗ Incorrect
The FROM instruction specifies the base image for the Docker container. 'python:3.8-slim' is a valid base image.
2fill in blank
mediumComplete the code to copy the current directory contents into the container.
ML Python
COPY [1] /app Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Copying a single file instead of the whole directory.
Using an absolute path from the container as source.
✗ Incorrect
COPY . /app copies all files from the current directory into the /app directory inside the container.
3fill in blank
hardFix the error in the command to install dependencies inside the container.
ML Python
RUN pip install [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the whole command including 'pip install' in the blank.
Omitting the '-r' flag.
✗ Incorrect
The correct pip command to install from a requirements file is 'pip install -r requirements.txt'. In Dockerfile RUN, only the arguments after pip install are needed, so '-r requirements.txt' is correct.
4fill in blank
hardFill both blanks to set the working directory and the command to run the app.
ML Python
WORKDIR [1] CMD ["python", "[2]"]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect path for WORKDIR.
Specifying the wrong script name in CMD.
✗ Incorrect
WORKDIR /app sets the working directory inside the container. CMD ["python", "app.py"] runs the app.py script when the container starts.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps file names to their sizes if size is greater than 1000 bytes.
ML Python
file_sizes = [1]: os.path.getsize([2]) for [3] in files if os.path.getsize([3]) > 1000
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in different parts of the comprehension.
Not using the variable as the key in the dictionary.
✗ Incorrect
The comprehension uses 'f' as the variable for each file name. The dictionary maps 'f' to its size using os.path.getsize(f).