The GPU-less AI Server: Running Heavy Python Models and Java Apps on a Budget So, you want to run a modern tech stack—a Java Spring Boot backend, a MySQL database, and a Python AI service (like Hugging Face or PyTorch)—all on a single cloud VM. You don’t have a $500/month GPU budget, and your Docker builds keep crashing with “No Space Left on Device.”

I just spent the day in the trenches fixing this. Here is the definitive guide to surviving the build.

  1. The Infrastructure: Don’t Starve Your CPU AI models are memory-hungry. If you are using a 1GB or 2GB RAM instance, stop now. You need at least 16GB RAM (Google Cloud e2-standard-4).

The Secret Weapon: Swap Space Even with 16GB, building Python AI containers can spike your memory and kill the process. We create a “safety net” using a Swap file.

Bash sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile

  1. The Docker Strategy: “Surgical” Python Builds Most people fail because their Python Docker image ends up being 5GB+. We need to be surgical. Instead of one massive pip install -r requirements.txt, we break it down to manage memory and disk pressure.

The “Gold Standard” AI Dockerfile: Dockerfile FROM –platform=linux/amd64 python:3.10-slim WORKDIR /app

1. Install light stuff first

RUN pip install –no-cache-dir flask gunicorn requests numpy pandas

2. Install Torch (CPU Version ONLY)

This prevents downloading 2GB of unnecessary CUDA/GPU drivers

RUN pip install –no-cache-dir torch –index-url https://download.pytorch.org/whl/cpu

3. Final dependencies

COPY requirements.txt . RUN pip install –no-cache-dir -r requirements.txt

COPY . . CMD [“python”, “app.py”]

  1. The “Disk Space” Trap You added space in the Google Cloud Console, but your terminal still says the disk is full? This is because resizing the hardware doesn’t automatically resize the “map” (partition) or the “room” (filesystem).

The 3-Step Rescue Sequence:

Grow the Partition: sudo growpart /dev/sda 1

Expand the Filesystem: sudo resize2fs /dev/sda1

Deep Clean Docker: sudo docker builder prune -f (This clears the hidden “scrap metal” from failed builds).

  1. The “MySQL Double-Start” Glitch On the very first run, MySQL initializes itself, creates users, and then restarts. If your Java app tries to connect during that 10-second restart window, it will crash.

The Fix: Always check your logs: sudo docker logs mysql-container-name. If it says “Ready for connections,” but your app is down, simply run:

Bash sudo docker compose restart your-java-app

  1. Summary Checklist for Success ✅ Architecture: Use python-slim images.

✅ Memory: Always enable a Swap file.

✅ Storage: Monitor with df -h and keep at least 50GB free for AI layer extraction.

✅ Efficiency: Use the CPU-specific index for PyTorch.

Final Thoughts Cloud providers give you the hardware, but you have to provide the “breathing room.” By managing your disk partitions and being specific about your Python dependencies, you can run a full AI-driven stack on a standard VM.