GoofyCubes
19

Chapter 19

Docker and Dockerfile Fundamentals

Learning Objective

Learn how GenAI services are packaged into portable containers.

What it means

Docker packages an application with its runtime, libraries, dependencies, and configuration into a container image. A Dockerfile is the recipe used to build that image. A container is a running instance of the image.

Why it matters

GenAI services depend on Python versions, AI libraries, API clients, and system packages. Docker ensures the application runs consistently across developer machines, QA, and production.

Healthcare Example

A clinical summary API using FastAPI and AI libraries can be packaged as a Docker image and deployed consistently across environments.

Common Commands

docker build -t healthcare-genai-api:1.0 .
docker run -p 8000:8000 healthcare-genai-api:1.0
docker ps
docker logs <container_id>

Code: Dockerfile for GenAI API

FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

Common Mistakes

  • Using latest tags without control.
  • Copying secrets into images.
  • Large images with unnecessary packages.
  • No health check.
  • Not pinning dependency versions.

Interview Q&A

Q: What is the difference between image and container?

A: An image is the blueprint; a container is the running instance of that image.

Q: Why use Docker?

A: Docker provides consistency, portability, and repeatable deployments by packaging code and dependencies together.

Architect Takeaway

Docker solves environment consistency. It is the packaging foundation for scalable GenAI deployment.