A complete, beginner-friendly Python development environment using Docker. Perfect for learning Python without the hassle of local setup!
- ๐ Python 3.11 - Latest stable Python version
- ๐ณ Docker & Docker Compose - Consistent environment across all systems
- ๐ Volume Mounting - Instant file sync between host and container
- ๐ฆ Package Management - Easy library installation via requirements.txt
- ๐ง Makefile Automation - Simple commands for common tasks
- ๐ Learning Examples - Step-by-step Python tutorials
- ๐ Comprehensive Docs - Detailed guides for beginners
- ๐ก๏ธ Security - Non-root user for safe execution
- Docker Desktop installed
- Windows: WSL2 (recommended) or Make
- Mac/Linux: Make (usually pre-installed)
# 1. Clone or download this repository
git clone <your-repo-url>
cd python-docker-template
# 2. Build and start the environment
make up
# 3. Run your first Python program
make run FILE=main.py
# 4. Try the learning examples
make run FILE=examples/01_variables.pyThat's it! You now have a complete Python development environment running in Docker.
# Environment Management
make up # Start the Docker container
make down # Stop and remove the container
make rebuild # Rebuild after adding new libraries
make status # Check container status
# Running Python Code
make run FILE=filename.py # Run a specific Python file
make python CMD='-c "print(42)"' # Run Python commands directly
make shell # Open interactive shell in container
# Library Management
make add PKG=requests # Add and install new package
make remove PKG=requests # Remove package from requirements
make list-packages # Show all installed packages
make update-deps # Update all packages to latest versions
# Environment Variables
make env-setup # Create .env template file
make env-check # Validate .env file format
# Development
make install # Rebuild container with new requirements
make logs # View container logs
make clean # Remove all containers and images
make help # Show all available commandspython-docker-template/
โโโ ๐ main.py # Your main Python file - start here!
โโโ ๐ examples/ # Learning examples (run these in order)
โ โโโ 01_variables.py # Variables and data types
โ โโโ 02_control_flow.py # If statements and loops
โ โโโ 03_functions.py # Functions and modules
โ โโโ 04_file_handling.py # Working with files
โ โโโ 05_libraries.py # Using external libraries
โ โโโ 06_environment_variables.py # Environment variables and .env files
โโโ ๐ docs/ # Comprehensive documentation
โ โโโ getting-started.md # Step-by-step setup guide
โ โโโ python-guide.md # Complete Python tutorial
โ โโโ docker-guide.md # Docker concepts explained
โ โโโ ...more guides... # Additional documentation
โโโ ๐ requirements.txt # Python packages (add new ones here)
โโโ ๐ Dockerfile # Container configuration
โโโ ๐ docker-compose.yml # Container orchestration
โโโ ๐ Makefile # Automation commands
โโโ ๐ README.md # This file
- Start Here: Read Getting Started Guide
- Learn Python: Follow Python Guide
- Practice: Run examples in order:
make run FILE=examples/01_variables.py make run FILE=examples/02_control_flow.py make run FILE=examples/03_functions.py make run FILE=examples/04_file_handling.py make run FILE=examples/05_libraries.py make run FILE=examples/06_environment_variables.py
- Understand Containers: Docker Guide
- Multi-container Setup: Docker Compose Guide
- Automation: Makefile Guide
- Daily Workflow: Development Workflow
- Adding Libraries: Library Management
- Best Practices: Security & Performance
# Add package automatically
make add PKG=requests
make add PKG='fastapi==0.104.1'
# Rebuild container
make rebuild-
Add to requirements.txt:
numpy==1.25.2 pandas==2.1.1 requests==2.31.0
-
Rebuild container:
make rebuild
-
Use in your code:
import numpy as np import pandas as pd import requests
# Create .env template
make env-setup
# Edit .env file with your values
# Then use in Python:from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv('API_KEY')
app_name = os.getenv('APP_NAME', 'DefaultApp')#!/usr/bin/env python3
# save as: my_script.py
def main():
print("Hello from Docker!")
name = input("What's your name? ")
print(f"Nice to meet you, {name}!")
if __name__ == "__main__":
main()Run with: make run FILE=my_script.py
import requests
from bs4 import BeautifulSoup
response = requests.get("https://httpbin.org/json")
data = response.json()
print(f"Origin IP: {data['origin']}")import pandas as pd
import numpy as np
# Create sample data
data = {
'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35],
'salary': [70000, 80000, 90000]
}
df = pd.DataFrame(data)
print(df.describe())Edit Dockerfile:
FROM python:3.12-slim # Change version hereEdit Dockerfile:
RUN apt-get update && apt-get install -y \
gcc \
git \
curl \
&& rm -rf /var/lib/apt/lists/*Edit docker-compose.yml:
services:
python-app:
ports:
- "8000:8000" # Expose ports
environment:
- DEBUG=1 # Add environment variablesContainer won't start?
make clean # Remove everything
make up # Start freshPermission denied?
- Windows: Run terminal as Administrator
- Mac/Linux:
sudo make up
File changes not reflected?
make rebuild # Rebuild containerImport errors?
- Add library to
requirements.txt - Run
make rebuild
- ๐ Check Troubleshooting Guide
- ๐ Read specific component guides in
docs/ - ๐ Review examples in
examples/
With this template, you can create:
- ๐ค Automation Scripts - File processing, system tasks
- ๐ Web Scrapers - Data collection from websites
- ๐ Data Analysis - CSV processing, statistics, visualization
- ๐ API Clients - Interact with REST APIs
- ๐ฎ Simple Games - Console-based games and puzzles
- ๐ฑ CLI Tools - Command-line utilities
- ๐ Reports - Automated report generation
Found a bug or want to add a feature?
- Fork this repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Python Software Foundation - For the amazing Python language
- Docker Inc. - For containerization technology
- Community Contributors - For examples and improvements
Ready to start coding? ๐
make up
make run FILE=main.pyHappy coding! ๐๐ณ