Sub topic 16
Deploying vLLM with a Container Image
Assume you know basic Docker commands, GPU memory concepts, and how to call an HTTP API. This chapter shows how to package a vLLM server in a container so the runtime, Python dependencies, and server configuration are reproducible.
Why use the vLLM container?
A vLLM container provides a ready-to-run environment with CUDA-compatible libraries, PyTorch, vLLM, and its command-line server. The host still supplies the NVIDIA driver and GPU devices. Docker isolates the application environment, but it does not remove the need for compatible host drivers.
The container should also access a persistent Hugging Face cache. Without a mounted cache, the image may download model weights again whenever the container is recreated.
docker run --runtime nvidia --gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:latest \
--model Qwen/Qwen2.5-1.5B-InstructThis command does the following:
--gpus allexposes the host GPUs to the container.-vmounts the local model cache at the path used inside the container.-p 8000:8000publishes the API port.--ipc=hostgives the process a larger shared-memory area, which can prevent multiprocessing failures.- The arguments after the image name are passed to
vllm serve.
The server listens on port 8000 and exposes an OpenAI-compatible API. Clients can use http://localhost:8000/v1 as their base URL.
Configure the deployment
Pin a tested image tag instead of relying on latest for a production deployment. Image versions can change the supported model architectures, CUDA requirements, and server behavior.
docker run --runtime nvidia --gpus all \
--name vllm-server \
--restart unless-stopped \
-v /srv/huggingface:/root/.cache/huggingface \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:<tested-tag> \
--model Qwen/Qwen2.5-1.5B-Instruct \
--max-model-len 4096 \
--gpu-memory-utilization 0.85Set the cache directory to a location with enough disk space. Model downloads can be many gigabytes. Treat the cache as data that must be backed up or repopulated during host replacement.
Understand the deployment boundary
The model weights live in the mounted cache, while the vLLM process runs inside the container. Requests enter through the published port and reach the OpenAI-compatible server.
Check the running container
Use Docker logs to inspect model loading and startup errors:
docker logs -f vllm-serverAfter the server reports that it is ready, send a request using the OpenAI Python client. Stop the deployment with docker stop vllm-server; remove it with docker rm vllm-server when you no longer need the container.
Exercise
Why should the Hugging Face cache be mounted from the host?
Show answer
Mounting the cache preserves downloaded model weights across container recreation and avoids repeating large downloads.