2025-07-25 22:33:56 +08:00
|
|
|
# This vLLM Dockerfile is used to build images that can run vLLM on both x86_64 and arm64 CPU platforms.
|
|
|
|
|
#
|
|
|
|
|
# Supported platforms:
|
|
|
|
|
# - linux/amd64 (x86_64)
|
|
|
|
|
# - linux/arm64 (aarch64)
|
|
|
|
|
#
|
|
|
|
|
# Use the `--platform` option with `docker buildx build` to specify the target architecture, e.g.:
|
|
|
|
|
# docker buildx build --platform=linux/arm64 -f docker/Dockerfile.cpu .
|
2025-03-28 16:36:31 +08:00
|
|
|
#
|
|
|
|
|
# Build targets:
|
|
|
|
|
# vllm-openai (default): used for serving deployment
|
|
|
|
|
# vllm-test: used for CI tests
|
|
|
|
|
# vllm-dev: used for development
|
|
|
|
|
#
|
|
|
|
|
# Build arguments:
|
2025-10-08 18:40:42 +01:00
|
|
|
# PYTHON_VERSION=3.13|3.12 (default)|3.11|3.10
|
2026-03-14 09:27:29 +08:00
|
|
|
# VLLM_CPU_X86=false (default)|true (for cross-compilation)
|
2026-02-15 14:33:08 +00:00
|
|
|
# VLLM_CPU_ARM_BF16=false (default)|true (for cross-compilation)
|
2025-03-28 16:36:31 +08:00
|
|
|
#
|
|
|
|
|
|
2025-07-28 19:02:39 +08:00
|
|
|
######################### COMMON BASE IMAGE #########################
|
|
|
|
|
FROM ubuntu:22.04 AS base-common
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /workspace
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
ARG PYTHON_VERSION=3.12
|
|
|
|
|
ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu"
|
2024-09-12 00:46:46 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
# Install minimal dependencies and uv
|
|
|
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
|
|
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
|
|
|
|
apt-get update -y \
|
2025-10-22 02:18:01 -07:00
|
|
|
&& apt-get install -y --no-install-recommends sudo ccache git curl wget ca-certificates \
|
2026-03-15 01:05:23 +08:00
|
|
|
gcc-12 g++-12 libtcmalloc-minimal4 libnuma-dev ffmpeg libsm6 libxext6 libgl1 jq lsof make xz-utils \
|
2025-03-28 16:36:31 +08:00
|
|
|
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12 \
|
|
|
|
|
&& curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
|
|
|
|
2025-11-20 02:37:09 +00:00
|
|
|
ENV CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12
|
2025-03-28 16:36:31 +08:00
|
|
|
ENV CCACHE_DIR=/root/.cache/ccache
|
2024-09-12 00:46:46 +08:00
|
|
|
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache
|
|
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
ENV PATH="/root/.local/bin:$PATH"
|
|
|
|
|
ENV VIRTUAL_ENV="/opt/venv"
|
2025-04-11 14:19:07 +08:00
|
|
|
ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV}
|
|
|
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
ENV UV_HTTP_TIMEOUT=500
|
2024-07-05 06:22:12 +08:00
|
|
|
|
2025-09-30 09:45:20 -04:00
|
|
|
# Install Python dependencies
|
2025-03-28 16:36:31 +08:00
|
|
|
ENV PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL}
|
|
|
|
|
ENV UV_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL}
|
|
|
|
|
ENV UV_INDEX_STRATEGY="unsafe-best-match"
|
|
|
|
|
ENV UV_LINK_MODE="copy"
|
2026-01-24 17:08:24 +00:00
|
|
|
|
|
|
|
|
# Copy requirements files for installation
|
|
|
|
|
COPY requirements/common.txt requirements/common.txt
|
|
|
|
|
COPY requirements/cpu.txt requirements/cpu.txt
|
|
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv pip install --upgrade pip && \
|
|
|
|
|
uv pip install -r requirements/cpu.txt
|
2024-07-05 06:22:12 +08:00
|
|
|
|
2025-07-25 22:33:56 +08:00
|
|
|
ARG TARGETARCH
|
|
|
|
|
ENV TARGETARCH=${TARGETARCH}
|
|
|
|
|
|
2025-07-28 19:02:39 +08:00
|
|
|
######################### x86_64 BASE IMAGE #########################
|
|
|
|
|
FROM base-common AS base-amd64
|
|
|
|
|
|
|
|
|
|
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4:/opt/venv/lib/libiomp5.so"
|
2025-07-25 22:33:56 +08:00
|
|
|
|
2025-07-28 19:02:39 +08:00
|
|
|
######################### arm64 BASE IMAGE #########################
|
|
|
|
|
FROM base-common AS base-arm64
|
2025-07-25 22:33:56 +08:00
|
|
|
|
2025-07-28 19:02:39 +08:00
|
|
|
ENV LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libtcmalloc_minimal.so.4"
|
|
|
|
|
|
|
|
|
|
######################### BASE IMAGE #########################
|
|
|
|
|
FROM base-${TARGETARCH} AS base
|
2024-06-14 00:33:14 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN echo 'ulimit -c 0' >> ~/.bashrc
|
2024-09-18 04:49:53 +02:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
######################### BUILD IMAGE #########################
|
|
|
|
|
FROM base AS vllm-build
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2025-10-28 14:25:44 +08:00
|
|
|
ARG max_jobs=32
|
2025-10-24 14:11:01 +02:00
|
|
|
ENV MAX_JOBS=${max_jobs}
|
|
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
ARG GIT_REPO_CHECK=0
|
2026-03-14 09:27:29 +08:00
|
|
|
# Support for cross-compilation with x86 ISA including AVX2 and AVX512: docker build --build-arg VLLM_CPU_X86="true" ...
|
|
|
|
|
ARG VLLM_CPU_X86=0
|
|
|
|
|
ENV VLLM_CPU_X86=${VLLM_CPU_X86}
|
2026-02-15 14:33:08 +00:00
|
|
|
# Support for cross-compilation with ARM BF16 ISA: docker build --build-arg VLLM_CPU_ARM_BF16="true" ...
|
|
|
|
|
ARG VLLM_CPU_ARM_BF16=0
|
|
|
|
|
ENV VLLM_CPU_ARM_BF16=${VLLM_CPU_ARM_BF16}
|
2024-06-04 01:39:50 +08:00
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /vllm-workspace
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2026-02-15 14:33:08 +00:00
|
|
|
# Validate build arguments - prevent mixing incompatible ISA flags
|
2026-03-14 09:27:29 +08:00
|
|
|
RUN if [ "$TARGETARCH" = "arm64" ] && [ "$VLLM_CPU_X86" != "0" ]; then \
|
2026-02-15 14:33:08 +00:00
|
|
|
echo "ERROR: Cannot use x86-specific ISA flags (AVX2, AVX512, etc.) when building for ARM64 (--platform=linux/arm64)"; \
|
|
|
|
|
exit 1; \
|
|
|
|
|
fi && \
|
|
|
|
|
if [ "$TARGETARCH" = "amd64" ] && [ "$VLLM_CPU_ARM_BF16" != "0" ]; then \
|
|
|
|
|
echo "ERROR: Cannot use ARM-specific ISA flags (ARM_BF16) when building for x86_64 (--platform=linux/amd64)"; \
|
|
|
|
|
exit 1; \
|
|
|
|
|
fi
|
|
|
|
|
|
2026-01-24 17:08:24 +00:00
|
|
|
# Copy build requirements
|
|
|
|
|
COPY requirements/cpu-build.txt requirements/build.txt
|
|
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv pip install -r requirements/build.txt
|
2024-08-08 21:24:52 +02:00
|
|
|
|
2024-10-17 19:25:06 +02:00
|
|
|
COPY . .
|
2026-01-24 17:08:24 +00:00
|
|
|
|
|
|
|
|
RUN if [ "$GIT_REPO_CHECK" != 0 ]; then bash tools/check_repo.sh ; fi
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
--mount=type=cache,target=/root/.cache/ccache \
|
2026-01-28 11:06:48 +08:00
|
|
|
--mount=type=cache,target=/vllm-workspace/.deps,sharing=locked \
|
2025-10-24 14:11:01 +02:00
|
|
|
VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38
|
2025-10-20 13:09:40 +02:00
|
|
|
|
2025-06-26 18:34:47 +08:00
|
|
|
######################### TEST DEPS #########################
|
|
|
|
|
FROM base AS vllm-test-deps
|
|
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /vllm-workspace
|
2025-06-26 18:34:47 +08:00
|
|
|
|
2026-01-24 17:08:24 +00:00
|
|
|
# Copy test requirements
|
|
|
|
|
COPY requirements/test.in requirements/cpu-test.in
|
|
|
|
|
|
|
|
|
|
RUN \
|
2025-06-26 18:34:47 +08:00
|
|
|
sed -i '/mamba_ssm/d' requirements/cpu-test.in && \
|
2025-11-20 02:37:09 +00:00
|
|
|
remove_packages_not_supported_on_aarch64() { \
|
2026-01-28 11:06:48 +08:00
|
|
|
case "$(uname -m)" in \
|
|
|
|
|
aarch64|arm64) \
|
|
|
|
|
sed -i '/decord/d' requirements/cpu-test.in; \
|
|
|
|
|
sed -i '/terratorch/d' requirements/cpu-test.in; \
|
|
|
|
|
;; \
|
|
|
|
|
esac; \
|
2025-11-20 02:37:09 +00:00
|
|
|
}; \
|
|
|
|
|
remove_packages_not_supported_on_aarch64 && \
|
2026-01-23 13:13:06 +00:00
|
|
|
sed -i 's/^torch==.*/torch==2.10.0/g' requirements/cpu-test.in && \
|
2025-11-28 14:43:18 +08:00
|
|
|
sed -i 's/torchaudio.*/torchaudio/g' requirements/cpu-test.in && \
|
|
|
|
|
sed -i 's/torchvision.*/torchvision/g' requirements/cpu-test.in && \
|
2025-06-26 18:34:47 +08:00
|
|
|
uv pip compile requirements/cpu-test.in -o requirements/cpu-test.txt --index-strategy unsafe-best-match --torch-backend cpu
|
|
|
|
|
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
2025-09-30 09:45:20 -04:00
|
|
|
uv pip install -r requirements/cpu-test.txt
|
2025-06-26 18:34:47 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
######################### DEV IMAGE #########################
|
|
|
|
|
FROM vllm-build AS vllm-dev
|
|
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /vllm-workspace
|
2025-03-28 16:36:31 +08:00
|
|
|
|
|
|
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
|
|
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
2026-03-15 01:05:23 +08:00
|
|
|
apt-get install -y --no-install-recommends vim numactl clangd-14
|
2025-12-18 14:36:49 +08:00
|
|
|
|
|
|
|
|
RUN ln -s /usr/bin/clangd-14 /usr/bin/clangd
|
2025-03-28 16:36:31 +08:00
|
|
|
|
|
|
|
|
# install development dependencies (for testing)
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
2025-09-30 09:45:20 -04:00
|
|
|
uv pip install -e tests/vllm_test_utils
|
2024-06-18 02:36:10 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
2024-08-08 21:24:52 +02:00
|
|
|
--mount=type=cache,target=/root/.cache/ccache \
|
2024-09-23 18:44:26 +02:00
|
|
|
--mount=type=bind,source=.git,target=.git \
|
2025-09-30 09:45:20 -04:00
|
|
|
VLLM_TARGET_DEVICE=cpu python3 setup.py develop
|
2025-03-28 16:36:31 +08:00
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
COPY --from=vllm-test-deps /vllm-workspace/requirements/cpu-test.txt requirements/test.txt
|
2025-06-26 18:34:47 +08:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv pip install -r requirements/dev.txt && \
|
|
|
|
|
pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
|
|
|
|
|
|
|
|
ENTRYPOINT ["bash"]
|
|
|
|
|
|
|
|
|
|
######################### TEST IMAGE #########################
|
2025-06-26 18:34:47 +08:00
|
|
|
FROM vllm-test-deps AS vllm-test
|
2024-04-02 13:07:30 +08:00
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /vllm-workspace
|
2024-05-23 17:08:58 +01:00
|
|
|
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
2026-01-28 11:06:48 +08:00
|
|
|
--mount=type=bind,from=vllm-build,src=/vllm-workspace/dist,target=dist \
|
2025-03-28 16:36:31 +08:00
|
|
|
uv pip install dist/*.whl
|
|
|
|
|
|
|
|
|
|
ADD ./tests/ ./tests/
|
|
|
|
|
ADD ./examples/ ./examples/
|
|
|
|
|
ADD ./benchmarks/ ./benchmarks/
|
2025-04-18 13:13:35 +08:00
|
|
|
ADD ./vllm/collect_env.py .
|
2025-07-02 18:50:25 -06:00
|
|
|
ADD ./.buildkite/ ./.buildkite/
|
2024-06-04 01:39:50 +08:00
|
|
|
|
2024-11-26 00:20:04 -08:00
|
|
|
# install development dependencies (for testing)
|
2025-03-28 16:36:31 +08:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
2025-09-30 09:45:20 -04:00
|
|
|
uv pip install -e tests/vllm_test_utils
|
2025-03-28 16:36:31 +08:00
|
|
|
|
|
|
|
|
######################### RELEASE IMAGE #########################
|
|
|
|
|
FROM base AS vllm-openai
|
|
|
|
|
|
2026-01-28 11:06:48 +08:00
|
|
|
WORKDIR /vllm-workspace
|
2025-03-28 16:36:31 +08:00
|
|
|
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
--mount=type=cache,target=/root/.cache/ccache \
|
2026-01-28 11:06:48 +08:00
|
|
|
--mount=type=bind,from=vllm-build,src=/vllm-workspace/dist,target=dist \
|
2025-03-28 16:36:31 +08:00
|
|
|
uv pip install dist/*.whl
|
2024-11-26 00:20:04 -08:00
|
|
|
|
2026-01-24 17:08:24 +00:00
|
|
|
# Add labels to document build configuration
|
|
|
|
|
LABEL org.opencontainers.image.title="vLLM CPU"
|
|
|
|
|
LABEL org.opencontainers.image.description="vLLM inference engine for CPU platforms"
|
|
|
|
|
LABEL org.opencontainers.image.vendor="vLLM Project"
|
|
|
|
|
LABEL org.opencontainers.image.source="https://github.com/vllm-project/vllm"
|
|
|
|
|
|
|
|
|
|
# Build configuration labels
|
|
|
|
|
ARG TARGETARCH
|
2026-03-14 09:27:29 +08:00
|
|
|
ARG VLLM_CPU_X86
|
2026-02-15 14:33:08 +00:00
|
|
|
ARG VLLM_CPU_ARM_BF16
|
2026-01-24 17:08:24 +00:00
|
|
|
ARG PYTHON_VERSION
|
|
|
|
|
|
|
|
|
|
LABEL ai.vllm.build.target-arch="${TARGETARCH}"
|
2026-03-14 09:27:29 +08:00
|
|
|
LABEL ai.vllm.build.cpu-x86="${VLLM_CPU_X86:-false}"
|
2026-02-15 14:33:08 +00:00
|
|
|
LABEL ai.vllm.build.cpu-arm-bf16="${VLLM_CPU_ARM_BF16:-false}"
|
2026-01-24 17:08:24 +00:00
|
|
|
LABEL ai.vllm.build.python-version="${PYTHON_VERSION:-3.12}"
|
|
|
|
|
|
2025-10-03 01:04:57 +08:00
|
|
|
ENTRYPOINT ["vllm", "serve"]
|