|
| 1 | +services: |
| 2 | + # Code Interpreter API |
| 3 | + api: |
| 4 | + image: ghcr.io/usnavy13/librecodeinterpreter:latest |
| 5 | + container_name: code-interpreter-api |
| 6 | + user: "1000:988" # Run as user with docker group access |
| 7 | + cap_add: |
| 8 | + - NET_ADMIN # Required for iptables management when WAN access is enabled |
| 9 | + ports: |
| 10 | + - "${API_PORT:-8000}:8000" |
| 11 | + - "${HTTPS_PORT:-443}:443" |
| 12 | + env_file: |
| 13 | + - .env |
| 14 | + environment: |
| 15 | + # Container-specific overrides (these override .env values) |
| 16 | + - API_HOST=0.0.0.0 |
| 17 | + - API_PORT=8000 |
| 18 | + - DOCKER_IMAGE_REGISTRY=ghcr.io/usnavy13/librecodeinterpreter |
| 19 | + |
| 20 | + # Service discovery (container names) |
| 21 | + - REDIS_HOST=redis |
| 22 | + - REDIS_PORT=6379 |
| 23 | + - MINIO_ENDPOINT=minio:9000 |
| 24 | + |
| 25 | + # Docker socket path inside container |
| 26 | + - DOCKER_BASE_URL=unix://var/run/docker.sock |
| 27 | + |
| 28 | + # SSL paths inside container |
| 29 | + - SSL_CERT_FILE=/app/ssl/cert.pem |
| 30 | + - SSL_KEY_FILE=/app/ssl/key.pem |
| 31 | + volumes: |
| 32 | + - /var/run/docker.sock:/var/run/docker.sock |
| 33 | + - ./logs:/app/logs |
| 34 | + - ./data:/app/data |
| 35 | + - ./ssl:/app/ssl |
| 36 | + depends_on: |
| 37 | + - redis |
| 38 | + - minio |
| 39 | + networks: |
| 40 | + - code-interpreter-network |
| 41 | + restart: unless-stopped |
| 42 | + stop_grace_period: 30s # Allow time to cleanup pooled containers |
| 43 | + healthcheck: |
| 44 | + test: |
| 45 | + [ |
| 46 | + "CMD", |
| 47 | + "sh", |
| 48 | + "-c", |
| 49 | + "curl -f -k https://localhost:443/health 2>/dev/null || curl -f http://localhost:8000/health 2>/dev/null || curl -f http://localhost:80/health || exit 1", |
| 50 | + ] |
| 51 | + interval: 30s |
| 52 | + timeout: 15s |
| 53 | + retries: 3 |
| 54 | + start_period: 15s |
| 55 | + |
| 56 | + # Redis for session management |
| 57 | + redis: |
| 58 | + image: redis:7-alpine |
| 59 | + container_name: code-interpreter-redis |
| 60 | + ports: |
| 61 | + # Expose to localhost for CLI tools |
| 62 | + - "127.0.0.1:6379:6379" |
| 63 | + environment: |
| 64 | + - REDIS_PASSWORD=${REDIS_PASSWORD:-} |
| 65 | + command: > |
| 66 | + sh -c " |
| 67 | + if [ -n \"$$REDIS_PASSWORD\" ]; then |
| 68 | + redis-server --requirepass $$REDIS_PASSWORD --appendonly yes --appendfsync everysec |
| 69 | + else |
| 70 | + redis-server --appendonly yes --appendfsync everysec |
| 71 | + fi |
| 72 | + " |
| 73 | + volumes: |
| 74 | + - redis-data:/data |
| 75 | + - ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro |
| 76 | + networks: |
| 77 | + - code-interpreter-network |
| 78 | + restart: unless-stopped |
| 79 | + healthcheck: |
| 80 | + test: ["CMD", "redis-cli", "ping"] |
| 81 | + interval: 30s |
| 82 | + timeout: 10s |
| 83 | + retries: 3 |
| 84 | + |
| 85 | + # MinIO for file storage |
| 86 | + minio: |
| 87 | + image: minio/minio:latest |
| 88 | + container_name: code-interpreter-minio |
| 89 | + ports: |
| 90 | + # API port for local testing |
| 91 | + - "127.0.0.1:9000:9000" |
| 92 | + # Console only, bound to localhost (access via SSH tunnel) |
| 93 | + - "127.0.0.1:${MINIO_CONSOLE_PORT:-9001}:9001" |
| 94 | + environment: |
| 95 | + - MINIO_ROOT_USER=${MINIO_ACCESS_KEY:-minioadmin} |
| 96 | + - MINIO_ROOT_PASSWORD=${MINIO_SECRET_KEY:-minioadmin} |
| 97 | + - MINIO_BROWSER_REDIRECT_URL=http://localhost:9001 |
| 98 | + command: server /data --console-address ":9001" |
| 99 | + volumes: |
| 100 | + - minio-data:/data |
| 101 | + networks: |
| 102 | + - code-interpreter-network |
| 103 | + restart: unless-stopped |
| 104 | + healthcheck: |
| 105 | + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] |
| 106 | + interval: 30s |
| 107 | + timeout: 10s |
| 108 | + retries: 3 |
| 109 | + |
| 110 | + # MinIO bucket initialization |
| 111 | + minio-init: |
| 112 | + image: minio/mc:latest |
| 113 | + container_name: code-interpreter-minio-init |
| 114 | + depends_on: |
| 115 | + - minio |
| 116 | + environment: |
| 117 | + - MINIO_ENDPOINT=minio:9000 |
| 118 | + - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-minioadmin} |
| 119 | + - MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-minioadmin} |
| 120 | + - MINIO_BUCKET=${MINIO_BUCKET:-code-interpreter-files} |
| 121 | + entrypoint: > |
| 122 | + /bin/sh -c " echo 'Waiting for MinIO to be ready...'; until mc alias set minio http://$$MINIO_ENDPOINT $$MINIO_ACCESS_KEY $$MINIO_SECRET_KEY; do |
| 123 | + echo 'MinIO not ready, waiting...'; |
| 124 | + sleep 2; |
| 125 | + done; echo 'MinIO is ready. Creating bucket if it does not exist...'; mc mb minio/$$MINIO_BUCKET --ignore-existing; echo 'Bucket setup complete.'; " |
| 126 | + networks: |
| 127 | + - code-interpreter-network |
| 128 | + |
| 129 | +volumes: |
| 130 | + redis-data: |
| 131 | + driver: local |
| 132 | + minio-data: |
| 133 | + driver: local |
| 134 | + |
| 135 | +networks: |
| 136 | + code-interpreter-network: |
| 137 | + driver: bridge |
| 138 | + ipam: |
| 139 | + config: |
| 140 | + - subnet: 172.20.0.0/16 |
| 141 | + |
| 142 | + # WAN-only network for execution containers that need internet access |
| 143 | + # This network is only created when ENABLE_WAN_ACCESS=true |
| 144 | + code-interpreter-wan: |
| 145 | + driver: bridge |
| 146 | + ipam: |
| 147 | + config: |
| 148 | + - subnet: 172.30.0.0/16 |
| 149 | + driver_opts: |
| 150 | + # Enable NAT for outbound internet access |
| 151 | + com.docker.network.bridge.enable_ip_masquerade: "true" |
| 152 | + # Disable inter-container communication |
| 153 | + com.docker.network.bridge.enable_icc: "false" |
| 154 | + labels: |
| 155 | + com.code-interpreter.managed: "true" |
| 156 | + com.code-interpreter.type: "wan-access" |
0 commit comments