Learning Docker

Jackson Hoffart

Learning Docker

  • 🚀 Docker makes our code portable & consistent across environments.
  • 🔄 We aim to “build once & run anywhere” — local, cloud, CI/CD, etc.
  • 🏗️ Docker containers help solve dependency conflicts and simplify collaboration.

“But, it works on my machine”

  • ❓ Has anyone ever had code that runs perfectly locally but fails elsewhere?
  • ❗ Reproducibility is hard across machines, OS versions, or teammates
  • ✅ Docker helps us create self-contained and portable environments that work anywhere1

1 Sort of.

So, what is Docker?

  • A containerization platform
  • Bundles code, libraries, and environment into one unit
  • Think of it as a “lightweight virtual computer”
  • Ensures consistency and reproducibility

Core Concepts

  • Image: The blueprint (like a saved environment)
  • Container: A running instance of an image
  • Dockerfile: Instructions for how to build an image
  • Registry: Where images are stored/shared (e.g. Docker Hub, GHCR)

Dockerfile: The Recipe

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "script.py"]

Build & Run Your Container

docker build -t my-python-app .
docker run my-python-app
  • build: creates an image from a Dockerfile
  • run: launches the container using that image

Common Data Science Use Cases

  • Share Jupyter notebooks with all dependencies
  • Run scheduled pipelines reliably
  • Train models in consistent environments
  • Ensure old analyses still work later
  • Integrate easily with CI/CD pipelines

Pro tips: Docker Best Practices

  • 📌 Pin all dependency versions
  • 📁 Use .dockerignore
  • 🧱 Layer instructions efficiently
  • 🏷️ Tag images clearly
  • 🔒 Avoid root unless absolutely necessary

Summary

  • ✅ Docker solves “it works on my machine”
  • ✅ Simple, readable files to define environments
  • ✅ Great fit for Python data science workflows
  • ✅ Paves the way for production & collaboration

Q&A

  • 💬 Questions, use cases, confusions?

Resources

  • Docker tutorial for beginners: https://docker-curriculum.com/
  • Docker documentation: https://docs.docker.com/