USB Printer Containerization
Transformed a local USB-connected Zebra label printer into a network-accessible printing service using Docker containerization, enabling any system on the network to print labels via REST API.
Context
Warehouse operations relied on a single USB-connected Zebra thermal label printer that could only be used by the machine it was physically attached to. Other systems — shipping label generators, asset tracking apps, and e-commerce workflows — all needed to print labels but had no way to reach the printer.
Challenge
USB printers are inherently local devices. Bridging the gap between a USB peripheral and network-accessible service requires direct hardware access from within a container, secure HTTPS access, and reliable print job handling. The solution had to work with existing Zebra ZPL label formats and integrate cleanly with other internal services.
Solution
A two-container Docker stack that turns the USB printer into a REST API:
Caddy Container (Reverse Proxy): Handles HTTPS with automatic TLS certificate management, domain routing, and security — forwarding requests to the internal FastAPI service.
FastAPI Container (Print Service): Exposes three print methods — web form upload, file upload API, and URL-based printing. The container mounts the USB device (/dev/usb/lp0) directly and communicates with the Zebra printer using PyUSB.
The architecture follows: Internet/Network → Caddy (HTTPS) → FastAPI → USB → Zebra Label Printer
┌──────────────┐ ┌──────────────┐ ┌──────────┐ ┌─────────┐
│ Network │────▶│ Caddy │────▶│ FastAPI │────▶│ Zebra │
│ Clients │ │ (HTTPS/TLS) │ │ (Print) │ │ Printer │
└──────────────┘ └──────────────┘ └──────────┘ └─────────┘
Port 443 Port 8000 /dev/usb/lp0
Deployment
Deployed on a dedicated host machine with the Zebra printer physically connected. Docker Compose orchestrates both containers with a single make run command. The Caddy reverse proxy automatically provisions TLS certificates, making the service securely accessible across the entire network without manual SSL configuration.
Impact
- Enabled network-wide label printing from any system or application
- Eliminated bottleneck of single-machine printer access
- Integrated with Dispatch shipping system for automated label printing
- Zero-downtime deployment with Docker Compose restart policies