# ๐Ÿณ ZPL2PDF - Docker Complete Guide Complete guide for using ZPL2PDF with Docker, including testing on all operating systems. --- ## ๐Ÿ“‹ Table of Contents 1. [Quick Start](#-quick-start) 2. [Understanding Docker Files](#-understanding-docker-files) 3. [Testing on All Operating Systems](#-testing-on-all-operating-systems) 4. [Usage Examples](#-usage-examples) 5. [Multi-Language Support](#-multi-language-support) 6. [Troubleshooting](#-troubleshooting) --- ## ๐Ÿš€ Quick Start ### Prerequisites ```bash # Install Docker Desktop # Windows/Mac: https://www.docker.com/products/docker-desktop # Linux: sudo apt-get install docker.io docker-compose ``` ### 1. Build the Image ```bash # Build ZPL2PDF Docker image docker build -t zpl2pdf:2.0.0 . ``` ### 2. Run Daemon Mode ```bash # Create watch and output folders mkdir watch output # Run in daemon mode docker run -d \ --name zpl2pdf-daemon \ -v ./watch:/app/watch \ -v ./output:/app/output \ -e ZPL2PDF_LANGUAGE=en-US \ zpl2pdf:2.0.0 ``` ### 3. Check Status ```bash # View logs docker logs zpl2pdf-daemon # Check health docker exec zpl2pdf-daemon /app/ZPL2PDF status ``` --- ## ๐Ÿ“ Understanding Docker Files ### **Dockerfile** = Build Recipe Defines **HOW** to build the ZPL2PDF container: ```dockerfile # Stage 1: Build the application FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build COPY . . RUN dotnet publish --runtime linux-x64 # Stage 2: Create minimal runtime image FROM mcr.microsoft.com/dotnet/runtime-deps:9.0 COPY --from=build /app/publish/ZPL2PDF . CMD ["/app/ZPL2PDF", "run", "-l", "/app/watch"] ``` **Benefits:** - โœ… Multi-stage build (smaller image ~200MB vs 1GB) - โœ… Self-contained executable (no .NET runtime needed) - โœ… Non-root user for security - โœ… Health checks built-in ### **docker-compose.yml** = Usage Configuration Defines **HOW TO USE** the container: ```yaml services: zpl2pdf: build: . volumes: - ./watch:/app/watch # Your folder -> Container folder - ./output:/app/output environment: - ZPL2PDF_LANGUAGE=pt-BR # Set language command: run -l /app/watch restart: unless-stopped ``` **Benefits:** - โœ… Easy configuration management - โœ… Multiple services in one file - โœ… One command to start everything - โœ… Environment variables ### **.dockerignore** = Optimization Excludes unnecessary files from Docker build: ``` bin/ obj/ *.md tests/ ``` **Benefits:** - โœ… Faster builds (less files to copy) - โœ… Smaller images - โœ… Better security (no secrets) --- ## ๐Ÿงช Testing on All Operating Systems ### Why Test with Docker? **WITHOUT Docker:** - โŒ Need separate PC for each OS - โŒ Complex setup for each platform - โŒ Hard to reproduce issues **WITH Docker:** - โœ… Test Linux on Windows! - โœ… Test different distributions - โœ… Reproducible environment - โœ… Same as production ### ๐Ÿง **Option 1: Test on Linux (Ubuntu)** ```bash # Build for Linux docker build -t zpl2pdf:linux-test . # Run interactive shell docker run -it --rm \ -v ./docs/Sample:/app/test \ zpl2pdf:linux-test \ /bin/bash # Inside container, test commands: /app/ZPL2PDF -help /app/ZPL2PDF -i /app/test/example.txt -o /tmp -n test.pdf /app/ZPL2PDF status ``` ### ๐ŸŽ **Option 2: Test on Alpine Linux (Lightweight)** Create `Dockerfile.alpine`: ```dockerfile FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine AS runtime # Install required packages RUN apk add --no-cache \ libgdiplus \ libintl \ icu-libs WORKDIR /app COPY build/publish/linux-x64/ZPL2PDF . RUN chmod +x /app/ZPL2PDF CMD ["/app/ZPL2PDF", "run", "-l", "/app/watch"] ``` ```bash # Build Alpine version docker build -f Dockerfile.alpine -t zpl2pdf:alpine . # Test docker run -it --rm zpl2pdf:alpine /app/ZPL2PDF -help ``` ### ๐Ÿ”ด **Option 3: Test on CentOS/RHEL** Create `Dockerfile.centos`: ```dockerfile FROM centos:8 # Install .NET runtime dependencies RUN dnf install -y \ libgdiplus \ glibc \ libicu WORKDIR /app COPY build/publish/linux-x64/ZPL2PDF . RUN chmod +x /app/ZPL2PDF CMD ["/app/ZPL2PDF", "run", "-l", "/app/watch"] ``` ```bash # Build CentOS version docker build -f Dockerfile.centos -t zpl2pdf:centos . # Test docker run -it --rm zpl2pdf:centos /app/ZPL2PDF -help ``` ### ๐ŸชŸ **Option 4: Test Windows Containers (Windows Only)** > **Note:** Windows containers only run on Windows hosts Create `Dockerfile.windows`: ```dockerfile FROM mcr.microsoft.com/dotnet/runtime:9.0-windowsservercore-ltsc2022 WORKDIR /app COPY build/publish/win-x64/ZPL2PDF.exe . CMD ["ZPL2PDF.exe", "run", "-l", "C:\\app\\watch"] ``` ```powershell # Build Windows container docker build -f Dockerfile.windows -t zpl2pdf:windows . # Test docker run -it --rm zpl2pdf:windows ZPL2PDF.exe -help ``` ### ๐Ÿงช **Option 5: Automated Testing with Docker Compose** ```bash # Run tests in container docker-compose --profile test up # Run tests for specific language docker run --rm \ -v ./tests:/src/tests \ -e ZPL2PDF_LANGUAGE=pt-BR \ zpl2pdf:2.0.0 \ dotnet test ``` --- ## ๐Ÿ’ก Usage Examples ### Example 1: Daemon Mode (Auto-Convert) ```bash # Using docker-compose (EASIEST) docker-compose up -d # Using docker run docker run -d \ --name zpl2pdf-daemon \ -v C:/ZPL:/app/watch \ -v C:/PDF:/app/output \ -e ZPL2PDF_LANGUAGE=en-US \ --restart unless-stopped \ zpl2pdf:2.0.0 ``` ### Example 2: Convert Single File ```bash # Copy file and convert docker run --rm \ -v ./input:/app/input:ro \ -v ./output:/app/output \ zpl2pdf:2.0.0 \ /app/ZPL2PDF -i /app/input/label.txt -o /app/output -n result.pdf -w 10 -h 5 -u cm ``` ### Example 3: Batch Conversion ```bash # Convert all files in a folder docker run --rm \ -v ./zpl-files:/app/watch:ro \ -v ./pdf-output:/app/output \ zpl2pdf:2.0.0 \ /app/ZPL2PDF run -l /app/watch ``` ### Example 4: Multi-Instance (Different Languages) ```bash # Start English instance docker run -d \ --name zpl2pdf-en \ -v ./watch-en:/app/watch \ -e ZPL2PDF_LANGUAGE=en-US \ zpl2pdf:2.0.0 # Start Portuguese instance docker run -d \ --name zpl2pdf-pt \ -v ./watch-pt:/app/watch \ -e ZPL2PDF_LANGUAGE=pt-BR \ zpl2pdf:2.0.0 # Start Spanish instance docker run -d \ --name zpl2pdf-es \ -v ./watch-es:/app/watch \ -e ZPL2PDF_LANGUAGE=es-ES \ zpl2pdf:2.0.0 ``` ### Example 5: Production Deployment ```yaml # docker-compose.prod.yml version: '3.8' services: zpl2pdf: image: zpl2pdf:2.0.0 container_name: zpl2pdf-prod volumes: - /srv/zpl/watch:/app/watch - /srv/zpl/output:/app/output - /srv/zpl/config:/app/config environment: - ZPL2PDF_LANGUAGE=en-US command: run -l /app/watch restart: always deploy: resources: limits: cpus: '2.0' memory: 1G reservations: cpus: '1.0' memory: 512M healthcheck: test: ["/app/ZPL2PDF", "status"] interval: 30s timeout: 10s retries: 3 logging: driver: "json-file" options: max-size: "10m" max-file: "3" ``` ```bash # Deploy to production docker-compose -f docker-compose.prod.yml up -d ``` --- ## ๐ŸŒ Multi-Language Support ### Supported Languages | Language | Code | Environment Variable | |----------|------|---------------------| | English | en-US | `ZPL2PDF_LANGUAGE=en-US` | | Portuguese | pt-BR | `ZPL2PDF_LANGUAGE=pt-BR` | | Spanish | es-ES | `ZPL2PDF_LANGUAGE=es-ES` | | French | fr-FR | `ZPL2PDF_LANGUAGE=fr-FR` | | German | de-DE | `ZPL2PDF_LANGUAGE=de-DE` | | Italian | it-IT | `ZPL2PDF_LANGUAGE=it-IT` | | Japanese | ja-JP | `ZPL2PDF_LANGUAGE=ja-JP` | | Chinese | zh-CN | `ZPL2PDF_LANGUAGE=zh-CN` | ### Set Language **Option 1: Environment Variable (Recommended)** ```bash docker run -d \ -e ZPL2PDF_LANGUAGE=pt-BR \ zpl2pdf:2.0.0 ``` **Option 2: Docker Compose** ```yaml environment: - ZPL2PDF_LANGUAGE=es-ES ``` **Option 3: At Build Time** ```dockerfile ENV ZPL2PDF_LANGUAGE=fr-FR ``` ### Test All Languages ```bash # Test English docker run --rm -e ZPL2PDF_LANGUAGE=en-US zpl2pdf:2.0.0 /app/ZPL2PDF -help # Test Portuguese docker run --rm -e ZPL2PDF_LANGUAGE=pt-BR zpl2pdf:2.0.0 /app/ZPL2PDF -help # Test Spanish docker run --rm -e ZPL2PDF_LANGUAGE=es-ES zpl2pdf:2.0.0 /app/ZPL2PDF -help ``` --- ## ๐Ÿ”ง Advanced Usage ### Custom Configuration ```bash # Create custom config cat > zpl2pdf.json <