tinycodinglm / code /code203.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame
1.94 kB
{"type": "session", "harness": "deepseek-harness", "id": "code203", "name": "Docker best practices"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What are Docker best practices for production?"}}
{"type": "message", "message": {"role": "assistant", "content": "**Dockerfile Optimization:**\n```dockerfile\n# Use specific base image\nFROM python:3.11-slim\n\n# Install dependencies first (cache layer)\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy source code\nCOPY . .\n\n# Non-root user\nRUN useradd -m appuser\nUSER appuser\n\n# Expose port\nEXPOSE 8000\n\n# Health check\nHEALTHCHECK CMD curl -f http://localhost:8000/health || exit 1\n\n# Run command\nCMD [\"gunicorn\", \"app:app\", \"--bind\", \"0.0.0.0:8000\"]\n```\n\n**Multi-stage Builds:**\n```dockerfile\n# Build stage\nFROM python:3.11 AS builder\nCOPY requirements.txt .\nRUN pip install --user -r requirements.txt\n\n# Runtime stage\nFROM python:3.11-slim\nCOPY --from=builder /root/.local /root/.local\nENV PATH=/root/.local/bin:$PATH\nCOPY . .\nCMD [\"python\", \"app.py\"]\n```\n\n**Best Practices:**\n- Use `.dockerignore`\n- Pin base image versions\n- Minimize layers\n- Use multi-stage builds\n- Run as non-root\n- Add health checks\n- Use `docker-compose` for local dev\n- Scan for vulnerabilities (`docker scout`, `trivy`)\n\n**Tips:**\n- Keep images small\n- Leverage build cache\n- Use BuildKit (`DOCKER_BUILDKIT=1`)\n- Separate dev/prod configs\n- Version your images"}}