Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jonatan-leal/ia-proyecto-sustituto/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Both Phase 2 (CLI) and Phase 3 (API) use Docker containers for consistent, reproducible deployments. This page covers Docker setup, configuration, and best practices for the diabetes prediction system.Docker Version: The project uses standard Docker (Docker Engine 20.10+)Base Image: Python 3.12 official image
Why Docker?
Consistency
Same environment on development, testing, and production machines
Isolation
Dependencies don’t conflict with other projects on the same machine
Portability
Run anywhere Docker is installed - Linux, Mac, Windows, cloud
Reproducibility
Dockerfile ensures anyone can build identical environment
Prerequisites
Install Docker
Install Docker Desktop (Mac/Windows) or Docker Engine (Linux):
- Windows
- macOS
- Linux
- Download Docker Desktop for Windows
- Run installer
- Enable WSL 2 backend when prompted
- Restart computer
- Verify:
Phase 2: CLI Docker Setup
Dockerfile Analysis
Line-by-Line Explanation
Line-by-Line Explanation
FROM python:3.12
- Base image: Official Python 3.12 from Docker Hub
- Includes Python, pip, and standard library
- Based on Debian Linux
- Sets
/appas the working directory - All subsequent commands run in
/app - Directory is created if it doesn’t exist
- Copies
train.pyfrom build context to/app/train.py ADDcan also extract archives (though not used here)
- Copies
predict.pyto container
- Copies dependencies list
- Installs Python packages
--no-cache-dir: Reduces image size by not caching packages- Packages: scikit-learn, pandas, imbalanced-learn, loguru, argparse
Dependencies (requirements.txt)
Building the Image
Running the Container
- Interactive Mode
- Detached Mode
- One-off Command
-i: Interactive (keep STDIN open)-t: Allocate pseudo-TTY (terminal)--name ai-container: Name the container/bin/bash: Command to run (bash shell)
Phase 3: API Docker Setup
Dockerfile Analysis
Key Differences from Phase 2
Key Differences from Phase 2
ADD .. /app
- Copies parent directory (entire fase-3 folder)
- Less selective than Phase 2 (which copied specific files)
- Includes all Python files, requirements.txt, etc.
- Default command when container starts
- Launches FastAPI application on port 80
- Unlike Phase 2, container runs automatically (no need for
/bin/bash)
Dependencies (requirements.txt)
Phase 3 has versioned dependencies for production stability, unlike Phase 2 which uses latest versions.
Building the Image
Running the API Container
-d: Detached mode (background)--name apirest-container: Container name-p 80:80: Port mapping (host:container)apirest: Image name
Data Management
Copying Files to Containers
Volume Mounting
For persistent data storage and easier file access:- Phase 2 with Volumes
- Phase 3 with Volumes
Container Management
Essential Commands
- Lifecycle
- Inspection
- Logs
- Execution
Image Management
Advanced Docker Configurations
Environment Variables
Resource Limits
Health Checks
Add to Dockerfile:Multi-stage Builds
Optimize image size:- Smaller final image (uses slim base)
- Faster pulls and deployments
- Reduced attack surface
Docker Compose (Optional)
For more complex setups:Best Practices
Troubleshooting
Port already allocated
Port already allocated
Error:
Bind for 0.0.0.0:80 failed: port is already allocatedSolutions:- Use different port:
- Stop conflicting container:
- Kill process using port:
Container exits immediately
Container exits immediately
Problem: Container stops right after startingDiagnosis:Common Causes:For Phase 3:
- No CMD in Dockerfile (Phase 2)
- Application crashes on startup
- Missing dependencies
Cannot connect to Docker daemon
Cannot connect to Docker daemon
Error:
Cannot connect to the Docker daemonSolutions:- Windows/Mac: Start Docker Desktop
- Linux: Start Docker service:
- Permissions (Linux):
Build fails - no space left
Build fails - no space left
Error:
no space left on deviceSolution: Clean up Docker resources:Security Considerations
-
Don’t include sensitive data in images:
-
Use secrets for credentials:
-
Scan images for vulnerabilities:
-
Keep base images updated:
Next Steps
CLI Usage
Detailed CLI operations and automation
API Deployment
Production API deployment strategies
Phase 2: CLI
CLI tools walkthrough
Phase 3: API
REST API implementation guide