How to Run vLLM in Docker for GPU API Serving

Vladimir Lomtev•
How to Run vLLM in Docker for GPU API Serving

To launch vLLM in Docker, you need a compatible GPU, a working driver, container access to the accelerator, and a supported model artifact. A reliable first launch checks these layers in order: host → container → model load → local API → real task. External users are connected only after access and restrictions are verified.

The guide was prepared by Vladimir Lomtsev's AI Studio on November 14, 2026 for IT teams deploying their first inference server. The example is intended for Linux and a compatible NVIDIA GPU; it is not a guide for any AMD, Mac, or CPU backend. The commands were checked against official sources, but the hardware launch was not performed as part of this article. The Qwen2.5 1.5B educational model is used to validate the infrastructure and is not claimed to be the best production model.

Contents

What’s included in the minimum server

vLLM handles requests to the model and manages their execution. Docker packages the environment, but it does not replace the GPU driver on the host. For NVIDIA, you need a mechanism to pass the accelerator into the container. Having a video card listed in the server spec does not automatically mean the application inside the image will see it.

The first-launch flow is simple: a local client connects to a host port, Docker forwards the connection to the vLLM container, and the model is loaded from an available source or a prepared directory. Before adding a gateway, access is limited to the loopback interface.

For production use, you also need weight storage, version control, observability, and a recovery procedure. This guide ends with a verified launch path and an acceptance plan; a multi-server cluster should be designed separately. General runtime differences are covered in the inference engine comparison.

Step 1. Check the host and compatibility

Run the following on the target host:

nvidia-smi
docker version

The first check should show an available NVIDIA GPU and driver. The second confirms that the Docker client and daemon are working. If an error appears here, do not start by changing model parameters: the problem is before vLLM.

For NVIDIA, set up Container Toolkit according to the manufacturer’s instructions. Packages and commands depend on the distribution and Docker configuration, so a universal one-line driver installation is not provided here.

Check the compatibility of the selected image with the GPU architecture and driver. Do not confuse the CUDA version shown by the host utility with the exact set of libraries inside the image. If there is a problem, save details from both layers.

Step 2. Pin the image and model

In the tutorial example, the published tag vllm/vllm-openai:v0.32.0 is used. This is a pinned version for reproducibility, not a recommendation to apply it automatically to all projects. Before a real launch, verify image availability, security requirements, and hardware support. Releases are available in the vLLM repository.

For a production release, save the image digest and model revision. The tag and repository name may not be enough to restore the environment exactly. If the model requires access confirmation, authenticate in an approved way; do not embed tokens in published configurations or logs.

The educational artifact Qwen/Qwen2.5-1.5B-Instruct was chosen because of its small size and existing model card. Business task quality is evaluated separately after the infrastructure is up and running.

Step 3. Prepare the key and cache directory

The following commands are intended for Bash. They create a cache directory and an environment file with a random key. The key is not printed to the terminal:

mkdir -p model-cache
umask 077
python3 - <<'PY'
from pathlib import Path
import secrets
path = Path('vllm.env')
if path.exists():
    raise SystemExit('vllm.env already exists; save the current key')
path.write_text('VLLM_API_KEY=' + secrets.token_urlsafe(32) + '\n')
PY

The environment file contains a secret and should not be placed in Git, the article, a support ticket, or a group chat. The Docker administrator on the host still has a high level of access; an environment variable is not a separate protected secret store.

The cache directory is needed so files do not have to be downloaded again after each container recreation. Make sure the disk has enough space not only for one weight file, but also for the full artifact, temporary data, and a future update.

Step 4. Start the container

Minimum configuration with local access:

docker run -d \
  --name local-vllm \
  --gpus all \
  --shm-size 2g \
  -p 127.0.0.1:8000:8000 \
  --env-file vllm.env \
  -v "$PWD/model-cache:/root/.cache/huggingface" \
  vllm/vllm-openai:v0.32.0 \
  --model Qwen/Qwen2.5-1.5B-Instruct \
  --served-model-name local-qwen \
  --dtype auto \
  --max-model-len 4096 \
  --gpu-memory-utilization 0.80

The --gpus all flag gives the container access to all available NVIDIA GPUs; in a shared environment, limit the list to allowed devices. The shared memory size 2g, 4096 context, and 0.80 memory share are tutorial settings, not universal requirements. They do not reserve a safe portion for any neighboring process.

The basic way to run the official image is described in Using Docker vLLM. In production, parameters should be checked against the --help output of the exact pinned image. For the first test, do not add --trust-remote-code unless you understand the need for and origin of the executable code.

Step 5. Read the logs and verify readiness

Check the container status and the latest messages:

docker ps -a --filter name=local-vllm
docker logs --tail 120 local-vllm

The first launch may take time to download files, initialize, and prepare execution. An open port does not prove the model is ready. Read the messages until you see a ready server or a specific error.

A short restart loop should not be hidden with an automatic restart policy. Find the cause first. For initialization errors, use the official vLLM Troubleshooting guide, while keeping track of the model, image, GPU, driver, and minimum configuration.

Step 6. Test the API from Python

The following client reads the key from the created file and connects to the local endpoint. Save it as check_vllm.py:

import json
from pathlib import Path
from urllib.request import Request, ProxyHandler, build_opener

values = {}
for line in Path('vllm.env').read_text().splitlines():
    if '=' in line and not line.startswith('#'):
        key, value = line.split('=', 1)
        values[key] = value
payload = {
    'model': 'local-qwen',
    'messages': [{'role': 'user', 'content': 'Name the capital of France.'}],
    'max_tokens': 40,
    'temperature': 0,
    'stream': False,
}
request = Request(
    'http://127.0.0.1:8000/v1/chat/completions',
    data=json.dumps(payload, ensure_ascii=False).encode(),
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + values['VLLM_API_KEY'],
    },
)
with build_opener(ProxyHandler({})).open(request, timeout=120) as response:
    result = json.load(response)
print(result['choices'][0]['message']['content'])
print('Completion:', result['choices'][0].get('finish_reason'))

A meaningful response confirms a short training path. Also check /v1/models, an invalid key, and an unknown model name. In the application, access denial, client error, and temporary execution unavailability should be distinct.

How to Read the Key Parameters

Parameter Purpose Interpretation Error
--model Model artifact source Confusing it with the public name in the request
--served-model-name Model name for the client Treating it as a guarantee of unchanged weights
--max-model-len Sequence length limit Considering only the user message
--gpu-memory-utilization Share of memory for instance planning Treating it as universal protection for other processes
--dtype Choosing the compute representation on a supported path Confusing it with arbitrary conversion to any format

Do not increase all limits at once. After a stable start, change one factor at a time: model, length, or parallelism. For resource selection, a separate breakdown of quantization and memory is useful.

What to Do About Common Errors

If the GPU is not visible inside the container, check device passthrough and the toolkit. If the weights do not download, check the source, access, and free disk space. If the model is not supported, you need a compatible runtime version or a different artifact; extra memory will not fix that.

If you hit OOM, determine when the failure occurs: loading, runtime preparation, or request processing. First try a smaller training artifact and a shorter sequence. Reducing load helps localize the cause, but it does not replace capacity planning.

If the API responds but the application errors out, check the model name, message format, and connection address. Inside another container 127.0.0.1 refers to its own network. Do not fix this by publishing the port to the entire internet.

What to Add Before Going Live

A local bind only protects the network path in this example. For employees or clients, set up an approved gateway, authentication, limits, and logging rules. Make sure technical endpoints do not expose unnecessary data.

Assign an owner for updates and keep the previous artifact. Server restarts, image changes, and model swaps should follow the documented procedure. It is useful to separate process validation from quality validation: a successful HTTP response does not necessarily mean usable output.

Enable observability before traffic grows. The documentation Production Metrics vLLM describes server metrics, and the material on enterprise AI access helps define the role of the gateway and interface.

First Release Checklist

  • The GPU is available on the host and inside the intended environment.
  • The image, model, and configuration are pinned and documented.
  • The weight cache persists independently of the container.
  • The key does not end up in the repository or application logs.
  • The port is available only through the approved route.
  • Both valid and invalid API requests have been tested.
  • A benchmark set for the business task has been completed.
  • Latency, memory, and errors have been measured under load.
  • The restart procedure and rollback conditions have been saved.

This is an acceptance template: record the result and a link to the actual log next to each item. Following the list does not replace your organization's requirements for a secure environment.

The mechanisms behind the server settings are explained in the guide to inference engines and acceleration. Before choosing hardware, it is useful to review the comparison of self-hosted inference and API.

Frequently Asked Questions

Can I use latest?

For a one-off experiment, yes, but a production release is better pinned by version and digest. Otherwise, a repeat run may get a different environment composition.

Do I need a Hugging Face token?

That depends on access to the selected model. For a restricted artifact or one that requires consent, use the allowed authorization; a public training example does not mean all models have the same conditions.

Why doesn't Docker solve all CUDA problems?

A container provides the user environment, but it runs through the host driver and hardware. Compatibility must be checked at both levels.

Can I connect dozens of users right away?

First you need load testing and access limits. The number of accounts does not determine request length, frequency, or actual parallelism.

How Vladimir Lomtev's AI Studio helps deploy a server

Vladimir Lomtev's AI studio can connect LLM deployment with data preparation, API integration, and result validation before launch. For a team, that means choosing a workflow, agreeing on criteria, and testing the right configuration within the permitted hosting setup.

The first step is to describe the process, the allowed data, and the required response time. Discuss the project.

How to Finish the First Launch

First, get a reproducible response from a small model through a closed local route. Then save the artifacts and configuration, and test your task and load. The move to a production server is determined by quality, availability, and manageability, not just by a container startup success message.

Request an audit

Share your contact details and we will follow up.

← All articles

Comments (0)

Loading comments…

Leave a comment
No registration required

Book a strategy call
for agentic operations

Tell us which workflow you want to improve. We will map feasibility, risks, and the fastest MVP path.

By submitting, you agree to our privacy policy

Contacts

Global Operations

Serving U.S. clients remotely
with private cloud and on-prem options

Strategy calls by request

We respond after reviewing your workflow context.

info@agentsunrise.pro

For partnership inquiries

Have a proposal?

Write to us in messengers

© 2026 AgentSunrise