Why is it important to keep Docker images small and optimized?
Think about how image size affects network and storage.
Smaller Docker images download faster and use less disk space, which speeds up deployment and reduces costs.
What will be the size shown for the optimized image after running docker image ls?
FROM python:3.12-slim RUN pip install flask COPY app.py /app/ CMD ["python", "/app/app.py"]
Consider the base image size and minimal additions.
The slim Python base image is about 123MB, and adding Flask and app code keeps it small.
Which Dockerfile change will best reduce the final image size?
FROM ubuntu:latest RUN apt-get update && apt-get install -y python3 python3-pip COPY . /app RUN pip3 install -r /app/requirements.txt CMD ["python3", "/app/app.py"]
Think about the base image size and unnecessary packages.
Using a smaller base image reduces unnecessary packages and overall image size.
You notice your Docker image is unexpectedly large after adding a build step. What is the most likely cause?
Think about leftover files from build steps.
Not cleaning temporary files during build causes them to remain in image layers, increasing size.
What is the main benefit of using multi-stage builds in Docker for image optimization?
Consider how multi-stage builds separate build and runtime environments.
Multi-stage builds let you compile or build in one stage, then copy only the necessary files to a clean, small final image.