Overview
The Docker setup includes:- Backend container: FastAPI server with Playwright
- Frontend container: Next.js web client
- Volume mounts: Persistent PDF storage
- Automatic restarts: Service resilience
Prerequisites
Install Docker
- Linux: Follow Docker Engine installation
- Windows/Mac: Install Docker Desktop
Quick start
Launch with Docker Compose
- Build the backend image
- Build the frontend image
- Start both containers in detached mode
- Create volume mounts for PDF storage
The
-d flag runs containers in the background. Omit it to see real-time logs.Docker Compose configuration
Thedocker-compose.yml file defines the multi-container setup:
docker-compose.yml
Service breakdown
Backend service
The backend container runs
web_server.py which starts the FastAPI server on port 8000.Frontend service
Dockerfile
The backend Dockerfile sets up the Python environment:Dockerfile
Key components
| Layer | Purpose |
|---|---|
python:3.10-slim | Lightweight Python base image |
apt-get install | System dependencies for Playwright |
pip install | Python packages from requirements.txt |
playwright install | Download Chromium browser |
COPY . . | Application code |
EXPOSE 8000 | Document port usage |
CMD | Default startup command |
Volume mounts
PDF storage
PDF/ directory to /app/PDF in the container, ensuring:
- PDFs persist after container restarts
- Files are accessible from the host system
- No data loss during updates
Environment variables
.env file for configuration without rebuilding the image.
Port mappings
| Service | Container Port | Host Port | Configurable |
|---|---|---|---|
| Backend | 8000 | 8000 | Yes |
| Frontend | 3000 | 3000 | Yes |
Changing ports
To change the exposed ports, modifydocker-compose.yml:
If you change the backend port, update the frontend’s API endpoint configuration to match.
Managing containers
Start services
Stop services
View logs
Restart services
Rebuild images
After code changes:Remove containers and volumes
Production considerations
Environment variables
For production, use Docker secrets or external secret management:Resource limits
Add resource constraints to prevent memory exhaustion:Adjust limits based on your server capacity and expected load. Image processing is memory-intensive.
Health checks
Add health checks for better reliability:Logging
Configure log rotation to prevent disk space issues:Networks
Create a custom network for service isolation:Reverse proxy
For production, use Nginx or Traefik as a reverse proxy:docker-compose.yml
Scaling
Multiple backend instances
Scale the backend for higher throughput:Troubleshooting
Build fails with Playwright errors
Issue: Playwright browser installation fails Solution: Increase Docker memory allocation (Docker Desktop → Settings → Resources → Memory → 4GB+)Container exits immediately
Issue: Missing dependencies or configuration errors Solution: Check logs:“Port already in use” error
Issue: Another service is using port 8000 or 3000 Solution:- Stop the conflicting service
- Or change the port mapping in
docker-compose.yml
PDFs not persisting
Issue: Volume mount not configured correctly Solution: Verify the mount indocker-compose.yml:
Frontend can’t connect to backend
Issue: Network configuration or CORS policy Solution:- Verify both containers are on the same network:
- Update CORS policy in
web_server.pyto include the frontend container name - Check that
depends_onis correctly set in frontend service
Out of disk space
Issue: Docker images and logs consuming disk space Solution: Clean up unused resources:Performance optimization
Image size reduction
Optimize the Dockerfile for smaller images:Build caching
Order Dockerfile commands to maximize cache hits:- System dependencies (rarely change)
- Python dependencies (change occasionally)
- Application code (change frequently)
Shared volumes for efficiency
Security
Non-root user
Run containers as non-root:Read-only filesystem
Secret management
Use Docker secrets for sensitive data:Docker secrets are only available in Swarm mode. For Compose-only deployments, use environment variables with caution.
Comparison with other deployment methods
| Aspect | Docker | Web App (Manual) | Desktop App |
|---|---|---|---|
| Setup time | Medium | High | Low |
| Portability | Excellent | Poor | Poor |
| Isolation | Yes | No | No |
| Updates | Easy (rebuild) | Manual | Manual |
| Resource usage | Higher | Lower | Lower |
| Multi-server | Easy (orchestration) | Complex | N/A |
| Production ready | Yes | Requires setup | No |