Before Docker, the app runs directly on the host, which may have different Python versions or missing dependencies. After Docker, the Dockerfile defines a container with a specific Python version and app code, ensuring consistent runtime everywhere.
### Before Docker: Running app directly
import time
def run_app():
print("App is running")
time.sleep(10)
run_app()
### After Docker: Dockerfile to containerize app
# Use official Python image
FROM python:3.11-slim
# Copy app code
COPY app.py /app/app.py
# Set working directory
WORKDIR /app
# Run the app
CMD ["python", "app.py"]