How to Run AI Apps with Docker on a VPS
There’s a special kind of pain only AI developers know: it works on your machine, you deploy it to the server, and it explodes. Wrong CUDA version. A Python package that compiled fine locally but refuses on the VPS. A model file that was supposed to be there and isn’t. You fix one thing, break two more, and by midnight you’re rebuilding an environment you built last week. When you run AI apps with Docker on a VPS, that whole class of problem disappears. The app, its dependencies, its CUDA libraries, and its config all live inside a container that behaves identically on your laptop and your server. Build once, pull on the VPS, and it runs. This guide covers why Docker fits AI workloads, the VPS specs that matter, full setup with GPU passthrough, a real docker-compose stack, and the security and cost realities nobody mentions upfront. Why Docker for AI Apps? (The Honest Pitch) AI apps are dependency nightmares. A typical stack pulls in PyTorch or llama.cpp, a specific CUDA toolkit, tokenizers, model weights in the tens of gigabytes, and a dozen pinned Python packages. On a bare server, one careless pip install and two projects start fighting over CUDA libraries. Docker fixes this with boring, reliable isolation: The tradeoff: a learning curve, plus a sharp edge or two in GPU setup (covered below). For AI apps, it isn’t close. New to servers? Our VPS hosting primer covers the fundamentals first. VPS Specs That Matter for AI-in-Docker Docker itself is light — your specs are driven entirely by what the AI app does inside the container. A chatbot UI sipping from an API needs almost nothing; a local 8B-parameter LLM needs serious RAM; fast inference needs a GPU. For CPU-only AI apps (API-backed chatbots, embedding pipelines, small models), RAM is king, then CPU cores, then disk: Tier Workload RAM CPU Disk Approx. cost Starter Chatbot UI, API proxies, n8n automations, small embedding jobs 4 GB 2 vCPU 80 GB SSD $6–12/mo Sweet spot Ollama with 7–8B models, RAG pipelines, Open WebUI + vector DB 16 GB 4–6 vCPU 200 GB NVMe $20–40/mo Heavy CPU 13B+ models on CPU, batch embedding, multiple AI services 32–64 GB 8–12 vCPU 400+ GB NVMe $50–100/mo GPU Fast local inference, image generation, fine-tuning 16–32 GB 4–8 vCPU 200+ GB NVMe $80–300+/mo Local LLMs are RAM-hungry in a way that surprises people: a 7B model in 4-bit quantization needs ~6–8 GB just for weights, plus server and OS overhead. That’s why the sweet spot starts at 16 GB. If serving models is your real goal, read our guide to running AI models on a VPS alongside this one. Start CPU-only, measure whether inference speed is actually your bottleneck, then pay the GPU tax — our roundup of cheap VPS options that don’t sacrifice performance covers the CPU tiers above. And budget 2x the disk you think you need: AI images run 5–10 GB, model weights 5–50 GB, and Docker’s build cache quietly eats the rest. Docker vs Bare Metal vs Virtualenv: Which Should You Pick? Approach Best for Biggest strength Biggest weakness Docker Most AI apps: chatbots, RAG, model servers, multi-service stacks Reproducible, isolated, one-command deploys Learning curve; overkill for single tiny scripts Bare metal Max-performance single workloads, squeezing every token/sec from one model Zero container overhead, simplest debugging Dependency conflicts; messy uninstalls Virtualenv Quick experiments, single Python scripts Zero setup, familiar Doesn’t isolate system deps (CUDA!); not reproducible across machines If the app has more than one moving part, or you ever want to run it on a second machine, use Docker. A single API-calling script? Virtualenv is fine. An Ollama server plus a web UI plus a vector database? That’s Docker’s home turf. Bare metal only wins when you’re chasing the last 2–3% of performance on one dedicated workload. How to Run AI Apps with Docker on a VPS: Step-by-Step Setup This assumes a fresh Ubuntu 22.04 or 24.04 VPS. If you haven’t hardened a fresh box yet, run through our new VPS setup checklist first — firewall, SSH keys, updates — then follow along as a non-root user with sudo. Step 1 — Install Docker and the Compose plugin Skip the distro’s outdated Docker package and use Docker’s official repository. Details change over time, so I’ll point you at Docker’s official Ubuntu install docs as the canonical reference — the short version: Then allow Docker without sudo (log out and back in after): Step 2 — GPU support: the NVIDIA Container Toolkit (GPU servers only) Skip this on a CPU-only VPS. With an NVIDIA GPU on the server, this is what makes it visible inside containers: The moment of truth — verify the GPU is reachable from inside a container: If your GPU appears in the output, passthrough works. If not, check troubleshooting first — it’s almost always a driver/toolkit version mismatch, not a Docker problem. Step 3 — Your first AI container: Ollama Ollama is the perfect first container: a real AI workload in one command. This pulls the image, starts the server, and keeps it running: Two deliberate choices: -p 127.0.0.1:11434:11434 binds the API to localhost only — never internet-exposed (see security) — and -v ollama-data:/root/.ollama keeps models in a named volume so they survive restarts. On a GPU server, add –gpus all and Ollama uses it automatically. That pull downloads ~4.7 GB — your first taste of why disk space matters. You’re now running a local LLM in a container on a VPS. Everything next makes this robust and multi-service. A Real Stack: Ollama + Open WebUI with Docker Compose Single containers are toys; real AI apps are stacks. The setup I run myself: Ollama serving models plus Open WebUI as a ChatGPT-style interface, wired together with Docker Compose. One YAML file, one command: The services talk over Docker’s internal network via service names (http://ollama:11434) — no host networking hacks. Both ports bind to 127.0.0.1 only; reach the UI through an SSH tunnel or reverse proxy. The
How to Run AI Apps with Docker on a VPS Read More »




