Skillversitas

Docker Generative AI

How to run AI models in Docker.

Docker for AI/ML

# Run Jupyter Notebook
docker run -d \
  --name jupyter \
  -p 8888:8888 \
  -v $(pwd):/home/jovyan/work \
  jupyter/scipy-notebook:latest

# Run TensorFlow
docker run -d \
  --name tensorflow \
  -p 8888:8888 \
  -v $(pwd):/notebooks \
  tensorflow/tensorflow:latest-jupyter

docker-compose.yml

version: '3.8'

services:
  jupyter:
    image: jupyter/scipy-notebook:latest
    ports:
      - "8888:8888"
    volumes:
      - ./notebooks:/home/jovyan/work
    environment:
      - JUPYTER_TOKEN=secret

  mlflow:
    image: ghcr.io/mlflow/mlflow:v2.8.0
    ports:
      - "5000:5000"
    volumes:
      - mlflow-data:/mlflow
    command: mlflow server --host 0.0.0.0

volumes:
  mlflow-data:

Use Case: AI Application

version: '3.8'

services:
  jupyter:
    image: jupyter/scipy-notebook:latest
    ports:
      - "8888:8888"
    volumes:
      - ./notebooks:/home/jovyan/work
    networks:
      - ai-net

  mlflow:
    image: ghcr.io/mlflow/mlflow:v2.8.0
    ports:
      - "5000:5000"
    volumes:
      - mlflow-data:/mlflow
    networks:
      - ai-net

  redis:
    image: redis:7-alpine
    networks:
      - ai-net

networks:
  ai-net:

volumes:
  mlflow-data:

Everyday Use Case

Case: A researcher needs to run an AI model.

# Run Jupyter
docker-compose up -d

# Access Jupyter
# http://localhost:8888

# Run the model
docker-compose exec jupyter python train.py

Best Practices

  1. GPU support: Use nvidia-docker
  2. Volume mount: For data and models
  3. Resource limits: For GPU and memory
  4. Health check: For monitoring

Conclusion

Docker makes it easy to run AI/ML applications. Use Jupyter for experiments and MLflow for tracking.