tinycodinglm / code /code203.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
1.94 kB
deepseek-harness trace
System 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 c...

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.

User

What are Docker best practices for production?

Assistant

Dockerfile Optimization:

dockerfile
# Use specific base image
FROM python:3.11-slim

# Install dependencies first (cache layer)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY . .

# Non-root user
RUN useradd -m appuser
USER appuser

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK CMD curl -f http://localhost:8000/health || exit 1

# Run command
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8000"]

Multi-stage Builds:

dockerfile
# Build stage
FROM python:3.11 AS builder
COPY requirements.txt .
RUN pip install --user -r requirements.txt

# Runtime stage
FROM python:3.11-slim
COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH
COPY . .
CMD ["python", "app.py"]

Best Practices:

  • Use .dockerignore
  • Pin base image versions
  • Minimize layers
  • Use multi-stage builds
  • Run as non-root
  • Add health checks
  • Use docker-compose for local dev
  • Scan for vulnerabilities (docker scout, trivy)

Tips:

  • Keep images small
  • Leverage build cache
  • Use BuildKit (DOCKER_BUILDKIT=1)
  • Separate dev/prod configs
  • Version your images