Deployment & Docker
What is Docker?
Docker is a platform for developing, shipping, and running applications in Containers. A container bundles your application along with all of its dependencies (Python, OpenCV, node_modules, system libraries) into a single, isolated package that guarantees it will run identically on any machine.
The Problem it Solves
"It works on my machine!" You build a machine vision app on your Windows laptop. But the factory runs Raspberry Pis (Linux ARM architecture). Without Docker, you'd spend hours installing Python 3.9, matching exact library versions, building C++ binaries, and debugging obscure OS dependencies on the Pi.
With Docker: You just pull an image and run it. The environment is perfectly replicated across 1 or 1,000 devices.
Key Concepts
1. The Dockerfile
The blueprint. A plain text file that contains the instructions to build the environment.
# Start from an official Python image
FROM python:3.9-slim
# Set the working directory inside the container
WORKDIR /app
# Install critical low-level system dependencies needed for OpenCV
RUN apt-get update && apt-get install -y libgl1-mesa-glx
# Copy your source code in via cache-friendly chunking
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# Tell the container what command to run
CMD ["python", "main.py"]
2. The Image
When you run docker build against a Dockerfile, it creates an Image. An image is a read-only, static snapshot of your app and its exact OS environment requirements.
3. The Container
When you run docker run my_image, you create a Container. A container is the live, running instance of an image.
4. Docker Compose
A tool for defining and running multi-container Docker applications. If your Edge device needs a Node.js server, a Python AI script, and a Postgres database, you write a docker-compose.yml file to spin them all up locally and connect them to the same bridged network with one command: docker-compose up.
VM vs. Container
- Virtual Machine (VM): Virtualizes the hardware. Runs an entire duplicate glowing operating system (Guest OS), which requires massive RAM and CPU overhead. Booting takes minutes.
- Container: Virtualizes the OS. Containers technically share the host machine's Linux Kernel. They are extremely lightweight, starting in milliseconds instead of minutes, perfect for limited Edge hardware.