The Python Slim Dev Container provides a lightweight, optimized, and production-ready development environment for Python applications. Designed with performance and maintainability in mind, it follows best practices for containerization, security, and code quality.
💫 Personal Journey & Motivation (Click to expand)
With a decade of experience in IT, I knew nothing at all about Python or AI two years ago. Diving head first into the depths with a deep understanding of programming logic, best practices, and principles, I got lost in a whole new ever-changing and fast-paced evolving world.
This highly minimal implementation of the most current best practices aims to add some color to those grey areas for anybody that feels they're in the same situation that I was in.
Feel free to contribute, just note that the coding governance and standards are extremely strictly aligned with the most current PEP guidelines and DRY modular architecture.
This is done so that at least I can follow the spaghetti packages and code implementations that needed to be ironed out.
- Multi-stage build with optimized layers for minimal footprint
- Poetry dependency management with clear separation of production/dev dependencies
- Remote development through SSH with automatic key display
- Industry-standard code quality with pre-commit hooks and CI/CD
- Database integration with PostgreSQL and proper volume management
- Python optimization flags for maximum performance
- Security features including non-root user, minimal exposed ports
- VS Code integration with curated extensions and settings
The only dependencies you need installed are:
| Component | Optimization | Standards | Security | Maintainability | Overall |
|---|---|---|---|---|---|
| Dockerfile | 9/10 ⭐ | 9/10 ⭐ | 8/10 ✅ | 9/10 ⭐ | 8.9/10 |
| docker-compose.yml | 8/10 ✅ | 9/10 ⭐ | 7/10 ✅ | 10/10 ⭐⭐ | 8.6/10 |
| devcontainer.json | 9/10 ⭐ | 10/10 ⭐⭐ | 9/10 ⭐ | 10/10 ⭐⭐ | 9.3/10 |
| .env | 10/10 ⭐⭐ | 10/10 ⭐⭐ | 7/10 ✅ | 10/10 ⭐⭐ | 9.3/10 |
| pyproject.toml | 9/10 ⭐ | 10/10 ⭐⭐ | 8/10 ✅ | 9/10 ⭐ | 9.2/10 |
| pre-commit config | 9/10 ⭐ | 10/10 ⭐⭐ | 10/10 ⭐⭐ | 9/10 ⭐ | 9.4/10 |
| CI/CD workflow | 8/10 ✅ | 9/10 ⭐ | 8/10 ✅ | 8/10 ✅ | 8.4/10 |
- Architecture Overview
- Key Technologies
- Project Structure
- Container Components
- Python Environment
- Code Quality & Standards
- Security Features
- CI/CD Integration
- Getting Started
- Configuration Files Explained
- HuggingFace Integration
- Contributing
This development container uses a microservices architecture with two primary services:
- Python Application Container: A slim Python environment with development tools
- PostgreSQL Database: Persistent data storage with proper volume mapping
Architecture Diagram (Click to expand)
┌─────────────────────────────────────────────────────────────┐
│ Docker Compose Network │
│ │
│ ┌─────────────────────────┐ ┌─────────────────────┐ │
│ │ │ │ │ │
│ │ Python Application │ │ PostgreSQL DB │ │
│ │ (VS Code Host) │◄────►│ │ │
│ │ │ │ │ │
│ └─────────────┬───────────┘ └─────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────┐ │
│ │ │ │
│ │ VS Code Extensions │ │
│ │ & Dev Environment │ │
│ │ │ │
│ └─────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
The architecture emphasizes:
- Performance: Minimal footprint with binary-only packages and slim images
- Reproducibility: Precisely pinned dependencies and explicit configurations
- Security: Non-root user by default with toggle option
- Standards: PEP-compliant tools with centralized configuration
| Category | Technology | Purpose |
|---|---|---|
| Container | Docker | Container runtime and build system |
| Docker Compose | Multi-service orchestration | |
| VS Code Devcontainers | Development environment integration | |
| Python | Python 3.11.8 | Runtime environment with optimization flags |
| Poetry | Dependency management | |
| PyYAML, Rich, Typer, Pydantic | Core libraries for application development | |
| Black, Ruff, MyPy | Code quality and type checking | |
| AI/ML | Hugging Face | AI model access and integration |
| Anthropic Claude API | AI assistant integration | |
| CI/CD | GitHub Actions | Automated testing and deployment |
| Pre-commit hooks | Local validation before commits |
The repository is organized into a hierarchical structure that separates concerns:
Contains project-wide configuration and documentation files:
pyproject.toml- Central configuration for Python tools.pre-commit-config.yaml- Git hooks automationREADME.md- Project documentation (this file)
Contains all container configuration files to define the development environment:
.devcontainer/devcontainer.json- VS Code dev container settings.devcontainer/Dockerfile- Container image definition.devcontainer/docker-compose.yml- Multi-container orchestration.devcontainer/.env- Environment variables and configuration
Contains GitHub-specific configuration files:
.github/dependabot.yml- Automated dependency updates.github/workflows/python-ci.yml- CI/CD workflow definition
Dockerfile (.devcontainer/Dockerfile)
# Multi-stage build for optimization
FROM python:3.11.8-slim-bullseye AS builder
└── Set optimization flags
└── Install Poetry and dependencies
└── Configure Python environment
FROM python:3.11.8-slim-bullseye
└── Copy Python packages from builder
└── Create non-root user
└── Set up SSH for remote access
└── Configure environment
Docker Compose (.devcontainer/docker-compose.yml)
Defines two services:
- app: Python development environment with VS Code integration
- db: PostgreSQL database with volume persistence
Environment Variables (.devcontainer/.env)
Contains essential configuration for the development environment:
- Container resource allocation
- Database credentials
- Development mode toggle
Poetry provides modern Python dependency management with:
- Clear separation between main and development dependencies
- Version pinning for reproducibility
- Lock file generation
- Virtual environment management
Example from pyproject.toml:
[tool.poetry.dependencies]
python = "^3.11"
pyyaml = "6.0"
click = "8.1.3"
rich = "10.16.2"
typer = "0.7.0"
pydantic = "1.10.8"Provides seamless development experience with:
- Preconfigured Python extensions
- Code formatting and linting
- Remote container access
- SSH server for external connections
Ensures code quality with automated checks:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
# Basic checks for common issues
- repo: https://github.com/psf/black
# Code formatting
- repo: https://github.com/astral-sh/ruff-pre-commit
# Fast linting
- repo: https://github.com/pre-commit/mirrors-mypy
# Type checking
- repo: https://github.com/hadolint/hadolint
# Dockerfile linting
- repo: https://github.com/gitleaks/gitleaks
# Secret scanningCentralizes configuration for multiple tools:
- Black for code formatting
- Ruff for fast linting
- MyPy for type checking
- Pytest for testing
- Non-root User: Container runs as
vscodeuser by default - SSH Key Management: Secure key generation for remote access
- Limited Port Exposure: Only essential ports exposed
- Secret Detection: Pre-commit hook to detect secrets in code
- Dependency Scanning: Dependabot for security updates
- Type Safety: MyPy for type checking
Automated testing and validation:
jobs:
lint:
# Code quality checks using pre-commit
test:
# Run pytest with coverage reportingAutomated dependency updates for:
- GitHub Actions workflows
- Dev container components
- Python dependencies
-
Prerequisites:
- Docker Desktop
- Visual Studio Code
- Dev Containers extension YOU SHOULD BE PROMPTED FOR THIS THOUGH
-
Clone and Open:
git clone https://github.com/yourusername/python-slim-dev-container.git cd python-slim-dev-container code .
-
Start Development:
- When prompted, click "Reopen in Container"
- The container will build and start automatically
- Your SSH key will be displayed in the terminal for remote connections
Click to expand file details
| File | Purpose | Implementation Details |
|---|---|---|
| pyproject.toml | Central configuration hub | Configures Black, Ruff, MyPy, Poetry |
| .pre-commit-config.yaml | Git hook automation | Ensures code quality before commits |
| devcontainer.json | VS Code integration | Configures editor and extensions |
| Dockerfile | Container definition | Multi-stage build with optimizations |
| docker-compose.yml | Service orchestration | Defines app and database services |
| .env | Environment variables | Configures container behavior |
| python-ci.yml | CI/CD workflow | Automates testing and validation |
| dependabot.yml | Dependency updates | Manages security and version updates |
Coming soon! The next phase of this project will include:
- HuggingFace model loading and inference
- Optimized container setup for ML workloads
- GPU passthrough configuration
- Model fine-tuning capabilities
- Integration with popular frameworks
SUGGESTIONS WELCOME FOR CROSS COMPATIBILITY LEAN OPTIMIZED SUGGESTIONS THAT ARE PERFORMANT.
Stay tuned for updates as we implement these exciting features!
Contributions are welcome and appreciated! Here's how you can help:
- Fork the repository
- Create a feature branch
- Commit your changes with descriptive messages
- Push to your branch
- Submit a Pull Request
Please ensure your code follows our standards by running pre-commit hooks locally:
pip install pre-commit
pre-commit installBuilt with ❤️ using Docker, Python, and VS Code Dev Containers
Docker • Microsoft • Python • Anthropic • HuggingFace

