This practical demonstrates how a Python-based application can be containerized using Docker. The application verifies a user’s SAP ID by comparing it with a predefined SAP ID stored inside the program.
The goal of this exercise is to demonstrate a complete DevOps-style workflow including:
• Application development
• Dependency management
• Docker container creation
• Image building
• Container execution
• Interactive user input handling
• Application testing inside a container
This practical uses an official lightweight Python Docker base image and installs required dependencies inside the container before executing the application.
Docker Desktop
Docker CLI
Python 3.10 Slim Base Image
NumPy Library
Windows Command Prompt
Git & GitHub
Application Development ↓ Dockerfile Creation ↓ Docker Image Build ↓ Container Execution ↓ Application Testing
Class-Test-5-Feb-SAPID/ │ ├── app.py ├── Dockerfile └── README.md
import numpy as np
stored_sapid = "500121943"
user_sapid = input("Enter your SAP ID: ")
if user_sapid == stored_sapid:
print("Matched")
else:
print("Not Matched")
FROM python:3.10-slim
WORKDIR /app
COPY app.py .
RUN pip install numpy
CMD ["python", "app.py"]
FROM python:3.10-slim
→ Uses the official lightweight Python 3.10 base image.
WORKDIR /app
→ Creates and sets the working directory inside the container.
COPY app.py .
→ Copies the Python application file from the host system into the container.
RUN pip install numpy
→ Installs the NumPy dependency inside the container.
CMD [“python”, “app.py”]
→ Defines the command executed when the container starts.
cd DevOps-Lab-Assignments
cd Class-Test-5-Feb-SAPID
docker build -t sapid-checker:500121943 .
Explanation
docker build → builds Docker image
-t → assigns image name and tag
sapid-checker → image name
500121943 → image tag (SAP ID)
. → current directory containing Dockerfile
docker images
Example Output
REPOSITORY TAG IMAGE ID sapid-checker 500121943 xxxxxxxxx
docker run -it sapid-checker:500121943
Explanation
docker run → starts container
-it → interactive terminal mode
sapid-checker → image name
The container will prompt the user:
Enter your SAP ID:
Input
500121943
Output
Matched
Input
123456
Output
Not Matched
Docker Base Image Usage
Dependency Installation Inside Container
Custom Docker Image Creation
Container Execution Workflow
Interactive Container Input Handling
Application Isolation Using Containers
Consistent runtime environment
Application portability
Lightweight virtualization
Fast deployment and startup
Dependency isolation
Simplified DevOps workflows
Developer writes Python application
↓
Dockerfile defines environment setup
↓
Docker builds custom image
↓
Image stored locally
↓
Container launched from image
↓
Application executed inside isolated environment
Dockerfile Code
Python Application Code
Docker Image Build Logs
Docker Images List
Container Execution Output
The Python SAP ID verification application was successfully containerized using Docker. A custom Docker image was created using the official Python base image and executed inside a container environment where the application was tested interactively.
This practical demonstrates how Docker can be used to package applications along with their dependencies into portable containers. Containerization ensures that applications run consistently across different environments, making Docker a fundamental tool in modern DevOps, cloud computing, and microservices architectures.