0
0
Dockerdevops~10 mins

Choosing small base images (alpine, slim) in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Choosing small base images (alpine, slim)
Start Dockerfile
Choose base image
Alpine
Add app files
Install dependencies
Build and run container
Check image size and performance
This flow shows how choosing a small base image like Alpine or Slim affects the Docker build and final image size.
Execution Sample
Docker
FROM python:3.12-alpine
COPY app.py /app/
RUN pip install flask
CMD ["python", "/app/app.py"]
This Dockerfile uses the small Alpine base image to build a Python app with Flask.
Process Table
StepActionBase Image SizeEffect on Image SizeResulting Image Size
1Start with python:3.12-alpine50 MBVery small base image50 MB
2Copy app.pyNo size changeAdds app code50 MB + app.py size
3Run pip install flaskAdds Flask and dependenciesIncreases size moderatelyApprox 70 MB total
4Set CMD to run appNo size changeSets container start commandApprox 70 MB total
5Build completeFinal image sizeSmall and efficient imageApprox 70 MB
6Compare with python:3.12-slimBase size ~120 MBLarger base imageApprox 140 MB total
💡 Build finishes with a small image using Alpine (~70 MB) versus larger Slim (~140 MB)
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Base Image SizeN/A50 MB50 MB50 MB50 MB
App SizeN/Aapp.py addedapp.py + Flask libsapp.py + Flask libsapp.py + Flask libs
Total Image SizeN/A50 MB + app.pyApprox 70 MBApprox 70 MBApprox 70 MB
Key Moments - 3 Insights
Why does the image size increase after 'pip install flask'?
Because installing Flask adds libraries and dependencies, increasing the image size as shown in step 3 of the execution_table.
Why is the Alpine base image smaller than the Slim base image?
Alpine is a minimal Linux distribution designed to be very small (~50 MB), while Slim is a stripped-down version of Debian but still larger (~120 MB), as shown in step 6.
Does copying app.py increase the image size significantly?
No, copying app.py adds only the size of that file, which is usually small compared to installed libraries, as seen in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the approximate total image size after installing Flask on Alpine?
A5 MB
B70 MB
C37 MB
D50 MB
💡 Hint
Check step 3 and 5 in the execution_table for image size after pip install flask.
At which step does the image size increase due to adding application code?
AStep 2
BStep 1
CStep 4
DStep 6
💡 Hint
Look at step 2 in the execution_table where app.py is copied.
If you switch from Alpine to Slim base image, how does the base image size change?
AIt stays the same
BIt becomes smaller
CIt becomes larger
DIt disappears
💡 Hint
Refer to step 6 in the execution_table comparing Alpine and Slim base sizes.
Concept Snapshot
Choosing small base images:
- Alpine: minimal (~50 MB), very small image size
- Slim: reduced Debian (~120 MB), larger than Alpine
- Smaller base means smaller final image
- Add only needed dependencies
- Smaller images start faster and use less space
Full Transcript
This visual execution shows how choosing a small base image like Alpine or Slim affects Docker image size. Starting with Alpine base image of about 50 MB, copying app code adds little size. Installing Flask adds libraries increasing size to about 70 MB total. Using Slim base image starts larger (~120 MB), resulting in a bigger final image (~140 MB). Key points: installing dependencies increases size, Alpine is smaller than Slim, copying app code adds minimal size. Choosing Alpine helps keep images small and efficient.