Vizuara AL Labs Presents
Machine Learning in Production
Lecture 8 Notes
What is Docker and why do we need
What will we cover in this lecture
1) Understanding Docker and containerization
2) Why Docker: challenges solved by Docker
3) Definition of Docker
4) Docker vs. Virtual Machines comparison
5) Key components of Docker
6) Real-
life analogies for Docker concepts
7) Simplified Docker architecture
Example flow: Dockerfile, image, container, registry
- Recognize the issues with monolithic ML scripts and learn to refactor them
into modular, organized code with clean folder structures and configuration
files for better maintainability.
- Implement best practices like test-
driven development (TDD) and use
setup files ([Link] or [Link]) to enable clean, scalable imports and
robust ML project workflows.
8.1) Docker: The Idea
Source : [Link]
Docker is an open-
source platform for developing, shipping, and running applications using
a technique called containerization.
It allows you to package your application and all its dependencies into a standardized
unit called a container, which can run consistently across different environments
whether it’s your laptop, development servers, or production cloud.
8.2) Why Docker
Problems Before Docker:
“It works on my machine, but not on the server.” Code breaking when moved between
environments due to differences in operating systems, libraries, or configurations.
Delays in deploying applications, especially when provisioning full servers for every new
app.
How Docker Solves It:
- Isolation & Consistency: Containers are independent from each other and the host
system, ensuring each app has exactly what it needs to run identically anywhere.
- Rapid Deployment: Containers start quickly and require few resources—
no full OS
setup needed for every app.
- Cost-
Effective: Multiple containers share the same host resources, consuming less
memory and CPU compared to virtual machines.
- Easy Rollback & Version Control: Docker tracks versions of your apps, allowing quick
rollbacks and easy updates.
- Security: Containers are isolated, reducing risk and controlling resource access
tightly.
8.3) What is Docker
Docker is a set of tools that automate the deployment of applications
inside lightweight containers, enabling apps to run efficiently and consistently in isolated
environments.
- Containers share the host OS kernel but run isolated, making them lightweight, fast
to start, and efficient compared to traditional virtual machines.
- Docker tools include Dockerfiles to build images, a container runtime to manage
containers, and registries like Docker Hub for storing and sharing container images.
8.4) Docker Vs Virtual Machine
Aspect Docker (Container) Virtual Machine (VM)
OS Usage Shares host OS kernel across Each VM runs its own guest OS
containers and kernel
Resource Usage Lightweight, minimal Heavy, requires full OS, higher
resources, fast boot time resource use
Performance High, with fast startup Lower, slower startup
Portability Easy to move containers VM images are large and
between systems harder to share
Application Setup App packaged with all Apps run on guest OS with
dependencies in one container separate dependencies
Security Good isolation but shares host Full isolation, stronger security
kernel, less secure for
privileged apps
8.5) Key Components in Docker
1) Docker Client: The interface (CLI) you use to issue
commands to Docker.
2) Docker Daemon (dockerd): The background service that
manages containers, images, networks, and storage.
3) Docker Image: A static blueprint or template for
containers—
it’s like a recipe card for building your app
environment.
4) Docker Container: A running instance of an image—
like the
takeout box holding the prepared meal; isolated and portable.
5) Dockerfile: A text file containing step-
by-
step instructions
to build a Docker image, similar to a recipe.
6) Docker Registry: A centralized storage for Docker images
such as Docker Hub, analogous to a library of recipe cards.
7) Docker Compose (Advanced): A tool to manage multi-
container applications, for example, running a web app and its
database together.
8) Networking and Storage: Tools to create virtual networks
that connect containers and volumes to persist data beyond
container lifecycles.
8.6) Docker Architecture (Simplified)
Let us Begin Implementation Task