0
0
Dockerdevops~30 mins

Choosing small base images (alpine, slim) in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Choosing Small Base Images with Docker
📖 Scenario: You are creating a Docker container for a simple Python application. To keep the container small and efficient, you want to choose a small base image.Small base images help your containers start faster and use less disk space, just like packing only the essentials for a trip instead of everything you own.
🎯 Goal: Build a Dockerfile that uses a small base image (python:3.12-alpine) to run a simple Python script.
📋 What You'll Learn
Create a Dockerfile starting with the python:3.12-alpine base image
Add a working directory /app
Copy a Python script named app.py into the container
Run the Python script using the CMD instruction
💡 Why This Matters
🌍 Real World
Small base images help developers create fast, efficient containers that use less disk space and bandwidth. This is important when deploying applications in the cloud or on limited resources.
💼 Career
Knowing how to choose and use small base images is a key skill for DevOps engineers and developers working with containerized applications.
Progress0 / 4 steps
1
Create the base Dockerfile with the alpine image
Create a Dockerfile that starts with the base image python:3.12-alpine using the FROM instruction.
Docker
Need a hint?

Use the FROM keyword followed by python:3.12-alpine to specify the base image.

2
Set the working directory and copy the Python script
Add a WORKDIR instruction to set the working directory to /app. Then add a COPY instruction to copy app.py from your local folder to the container's /app directory.
Docker
Need a hint?

Use WORKDIR /app to set the folder inside the container. Use COPY app.py /app/ to copy the file.

3
Add the command to run the Python script
Add a CMD instruction to run the Python script app.py using python.
Docker
Need a hint?

Use CMD ["python", "app.py"] to run the script when the container starts.

4
Build and run the Docker container
Write the command to build the Docker image named small-python-app from the current directory. Then write the command to run the container from this image.
Docker
Need a hint?

Use docker build -t small-python-app . to build and docker run small-python-app to run.