xiaohongshu
xiaohongshu
docker-deployment
Comprehensive Docker containerization for Python/FastAPI applications, from simple hello-world apps to production-ready deployments with security best practices, multi-stage builds, and optimized configurations. Use when containerizing Python/FastAPI applications for development, testing, or prod...
Full skill instructions
This skill provides comprehensive support for containerizing Python/FastAPI applications, from simple hello-world apps to production-ready deployments with security best practices, including prerequisite verification and resource configuration for AI services.
Before using this skill, verify your Docker installation and system resources:
# Check Docker version
docker --version
# Check Docker Compose version
docker compose version
# Test Docker functionality
docker run hello-world
# Check Docker system info
docker info
For AI services and production deployments:
# For Linux
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# For AI services with GPU support (Linux)
sudo apt install nvidia-container-toolkit
sudo systemctl restart docker
Use this skill when you need to:
When deploying AI services or resource-intensive applications, configure Docker resources appropriately:
# Memory and CPU limits
docker run -m 4g --cpus=2.0 my-ai-service
# With GPU support (NVIDIA)
docker run --gpus all -m 8g --cpus=4.0 my-ai-service
# PID limits for container isolation
docker run --pids-limit 100 my-ai-service
version: "3.8"
services:
ai-service:
image: my-ai-service:latest
deploy:
resources:
limits:
cpus: '4.0'
memory: 8G
pids: 200
reservations:
cpus: '2.0'
memory: 4G
# For GPU support
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
For Docker Desktop:
For a simple Python/FastAPI application:
# syntax=docker/dockerfile:1
# === Build stage: Install dependencies and create virtual environment ===
FROM python:3.11-slim AS builder
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app
# Install system dependencies if needed
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# === Final stage: Create minimal runtime image ===
FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
# Create non-root user for security
RUN useradd --create-home --shell /bin/bash appuser
# Copy Python dependencies from builder stage
COPY --from=builder --chown=appuser:appuser /root/.local /home/appuser/.local
# Copy application code
COPY --chown=appuser:appuser . .
# Switch to non-root user
USER appuser
# Make sure scripts in .local are usable
ENV PATH=/home/appuser/.local/bin:$PATH
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
For enhanced security in production:
# syntax=docker/dockerfile:1
# === Build stage: Install dependencies and create virtual environment ===
FROM dhi.io/python:3.11-alpine3.18-dev AS builder
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PATH="/app/venv/bin:$PATH"
WORKDIR /app
RUN python -m venv /app/venv
COPY requirements.txt .
# Install any additional packages if needed using apk
RUN apk add --no-cache gcc musl-dev && \
pip install --no-cache-dir -r requirements.txt
# === Final stage: Create minimal runtime image ===
FROM dhi.io/python:3.11-alpine3.18
WORKDIR /app
ENV PYTHONUNBUFFERED=1
ENV PATH="/app/venv/bin:$PATH"
# Create non-root user for security
RUN addgroup -g 1001 -S appgroup && \
adduser -S appuser -u 1001 -G appgroup
COPY app.py ./
COPY --from=builder /app/venv /app/venv
# Switch to non-root user
USER appuser
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
For applications requiring databases and other services:
version: "3.8"
services:
web:
build:
context: .
target: final
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://user:password@db:5432/myapp
- REDIS_URL=redis://redis:6379
env_file:
- .env
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
db:
image: postgres:15
restart: unless-stopped
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=myapp
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d myapp"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data:
For production environments with secrets management:
version: "3.8"
services:
web:
build:
context: .
target: final
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://user:password@db:5432/myapp
env_file:
- .env
secrets:
- db_password
depends_on:
db:
condition: service_healthy
restart: unless-stopped
# Additional security settings
read_only: true
tmpfs:
- /tmp
- /run
cap_drop:
- ALL
db:
image: postgres:15
restart: unless-stopped
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=myapp
- POSTGRES_USER=user
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
secrets:
- db_password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d myapp"]
interval: 10s
timeout: 5s
retries: 5
cap_drop:
- ALL
secrets:
db_password:
file: ./secrets/db_password.txt
volumes:
postgres_data:
See DOCKER-SCRIPTS.md for automated Dockerfile generation scripts.
See SECURITY.md for detailed security best practices and production hardening techniques.
See OPTIMIZATION.md for performance tuning and optimization strategies.
See PREREQUISITES.md for system requirements, Docker installation validation, and resource allocation guidelines for AI services.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience