Quiz 2

Docker for Data Science

421 words
2 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Docker for Data Science ## 🎯 Learning Objectives - Build Docker images for data science applications - Use Docker volumes for persistent data - Manage multi-container applications with Docker Compose - Deploy ML models as Docker containers ## 📖 Core Content ### 4.1 What is Docker? Docker packages an application...

Docker for Data Science

🎯 Learning Objectives

  • Build Docker images for data science applications
  • Use Docker volumes for persistent data
  • Manage multi-container applications with Docker Compose
  • Deploy ML models as Docker containers

📖 Core Content

4.1 What is Docker?

Docker packages an application with all its dependencies into a container — a lightweight, standalone, executable unit. It solves "it works on my machine" by ensuring identical environments across development, testing, and production. (Diagram)

4.2 Dockerfile for a Data Science App

dockerfile
# Dockerfile
FROM python:3.9-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python packages
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Expose port for API
EXPOSE 8000
# Run the application
CMD ["python", "app.py"]

4.3 Docker Commands

bash
# Build image
docker build -t ml-model:v1 .
# Run container
docker run -p 8000:8000 -v $(pwd)/data:/app/data ml-model:v1
# List containers
docker ps -a
# Stop container
docker stop <container-id>
# Remove unused images
docker system prune -a

4.4 Docker Compose for ML Stack

yaml
# docker-compose.yml
version: '3.8'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - ./data:/app/data
    environment:
      - MLFLOW_TRACKING_URI=http://mlflow:5000
  mlflow:
    image: ghcr.io/mlflow/mlflow:v2.3.0
    ports:
      - "5000:5000"
    command: mlflow server --host 0.0.0.0 --port 5000
    volumes:
      - ./mlruns:/mlflow/mlruns

📝 Practice Questions

Q1: What's the difference between a Docker image and a container?
An image is a read-only template (like a class or blueprint). A container is a running instance of an image (like an object). You can build one image and run many containers from it. Images are immutable; containers have a writable layer. Q2: Why use Docker for data science projects?
  1. Reproducibility: Exact same environment everywhere
  2. Dependency isolation: ML packages often conflict (TensorFlow 1 vs 2)
  3. Deployment: Package model as container → deploy anywhere
  4. Collaboration: New team members just run docker build
  5. Scaling: Containers orchestrate easily (Kubernetes) Q3: What is a Docker volume and why use it?
A volume mounts a directory from the host into the container. Without volumes, data written inside a container is lost when the container stops. Volumes persist data: "docker run -v /host/data:/app/data" makes /host/data accessible at /app/data inside the container. Essential for model files, datasets, and databases. Join Discord PreviousJupyter & IDENextAPIs & Web Scraping
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.