Overview
Platzi Viewer can be deployed as a Docker container, providing an isolated and reproducible environment. The application runs on Python 3.13-slim with only the essential runtime dependencies.Prerequisites
- Docker 20.10 or higher
- Docker Compose v2.0 or higher
- Google Service Account credentials (JSON file)
Quick Start
Create runtime data directory
Docker Compose Configuration
Thedocker-compose.yml file defines the service configuration:
Environment Variables
Required Variables
Path to the Google Service Account JSON file inside the container.Default:
/secrets/service_account.jsonNetwork Configuration
The host address to bind the server to. Use
0.0.0.0 to accept connections from any network interface.The port number the server listens on.
The hostname displayed in server logs and used for URL generation.
Storage Configuration
Directory inside the container where application data is stored (progress, cache).
Root directory of the application code inside the container.
Maximum size (in bytes) allowed for the progress.json file (2MB default).
Python Configuration
Prevents Python from writing
.pyc files.Forces Python output to be unbuffered for real-time logging.
Authentication Methods
Option A: Mount Service Account File (Recommended)
Mount the credentials file as a read-only volume:Option B: Environment Variable
Pass the entire JSON as an environment variable using an.env file:
-
Create a
.envfile: -
Update
docker-compose.yml:
Volume Mounts
Application Data Volume
progress.json- User progress trackingcourses_cache.json- Cached course structure from Drive
Secrets Volume
:ro flag mounts the directory as read-only for security.
Dockerfile Details
The Dockerfile uses a multi-stage approach optimized for production:Building from Source
Build the Docker Image
Run without Docker Compose
Container Management
View Logs
Stop the Container
Restart the Container
Update and Rebuild
Health Checks
The container includes a built-in health check that monitors the/api/health endpoint:
- Interval: Every 30 seconds
- Timeout: 5 seconds
- Start Period: 15 seconds (grace period)
- Retries: 3 attempts before marking unhealthy
Networking
Expose on Different Port
Change the host port mapping indocker-compose.yml:
Access from Other Machines
SetPUBLIC_HOST to your server’s IP or domain:
Production Considerations
Security Best Practices
- Never commit
service_account.jsonto version control - Use
.dockerignoreto exclude sensitive files - Run containers with limited privileges
- Use Docker secrets for production deployments
- Keep the base image updated:
docker-compose pull
Performance Tuning
- The container uses
ThreadingHTTPServerfor concurrent request handling - Mount
/datavolume on fast storage (SSD) for better cache performance - Consider using a reverse proxy (nginx/Caddy) for SSL termination
Monitoring
View real-time resource usage:Troubleshooting
Container Won’t Start
Check logs for errors:Permission Denied Errors
Ensure theruntime-data directory is writable:
Can’t Connect to Drive API
Verify credentials are mounted correctly:Port Already in Use
Change the host port or stop conflicting services:Next Steps
Desktop App
Run as a native desktop application
Portable Executable
Build standalone Windows executables