| 1 |
# syntax=docker/dockerfile:1.7 |
| 2 |
# |
| 3 |
# Multi-stage Dockerfile for PyVista. |
| 4 |
# |
| 5 |
# Targets: |
| 6 |
# - slim : Minimal Python image with PyVista installed (off-screen). |
| 7 |
# - jupyter : JupyterLab image with PyVista + Trame for interactive |
| 8 |
# in-notebook rendering. |
| 9 |
# |
| 10 |
# Build from the repository root: |
| 11 |
# |
| 12 |
# docker build -f docker/Dockerfile --target slim -t pyvista:slim . |
| 13 |
# docker build -f docker/Dockerfile --target jupyter -t pyvista:jupyter . |
| 14 |
# |
| 15 |
# Override the Python version (must match a supported VTK wheel): |
| 16 |
# |
| 17 |
# docker build --build-arg PY_VERSION=3.12 \ |
| 18 |
# -f docker/Dockerfile --target jupyter -t pyvista:jupyter . |
| 19 |
|
| 20 |
ARG PY_VERSION=3.13 |
| 21 |
|
| 22 |
|
| 23 |
# --------------------------------------------------------------------------- |
| 24 |
# Stage 1: build the PyVista wheel from the source tree in the build context. |
| 25 |
# Produces /build/dist/pyvista-*.whl, which the runtime stages install. This |
| 26 |
# keeps build tooling out of the final images and avoids any pre-build step |
| 27 |
# outside of Docker. |
| 28 |
# --------------------------------------------------------------------------- |
| 29 |
FROM python:${PY_VERSION}-slim AS builder |
| 30 |
|
| 31 |
WORKDIR /build |
| 32 |
|
| 33 |
RUN --mount=type=cache,target=/root/.cache/pip \ |
| 34 |
pip install --upgrade pip build |
| 35 |
|
| 36 |
COPY . /build |
| 37 |
|
| 38 |
RUN python -m build --wheel --outdir /build/dist |
| 39 |
|
| 40 |
|
| 41 |
# --------------------------------------------------------------------------- |
| 42 |
# Stage 2: slim runtime. PyVista only, no Jupyter, off-screen by default. |
| 43 |
# --------------------------------------------------------------------------- |
| 44 |
FROM python:${PY_VERSION}-slim AS slim |
| 45 |
|
| 46 |
LABEL org.opencontainers.image.title="PyVista (slim)" |
| 47 |
LABEL org.opencontainers.image.description="Minimal PyVista runtime image for off-screen rendering." |
| 48 |
LABEL org.opencontainers.image.source="https://github.com/pyvista/pyvista" |
| 49 |
LABEL org.opencontainers.image.licenses="MIT" |
| 50 |
|
| 51 |
ENV PYVISTA_OFF_SCREEN=true \ |
| 52 |
PIP_DISABLE_PIP_VERSION_CHECK=1 \ |
| 53 |
PIP_NO_CACHE_DIR=1 \ |
| 54 |
NVIDIA_VISIBLE_DEVICES=all \ |
| 55 |
NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute |
| 56 |
|
| 57 |
# Runtime libraries VTK dlopens for off-screen rendering. libegl1 enables |
| 58 |
# EGL so the image uses GPU acceleration when run with the NVIDIA container |
| 59 |
# runtime, and falls back to Mesa llvmpipe software rendering on CPU-only |
| 60 |
# hosts via the libgl1/GLX path. |
| 61 |
RUN apt-get update \ |
| 62 |
&& apt-get install -y --no-install-recommends \ |
| 63 |
libopengl0 \ |
| 64 |
libgl1 \ |
| 65 |
libegl1 \ |
| 66 |
libxrender1 \ |
| 67 |
&& rm -rf /var/lib/apt/lists/* |
| 68 |
|
| 69 |
COPY --from=builder /build/dist/pyvista-*.whl /tmp/ |
| 70 |
|
| 71 |
RUN pip install /tmp/pyvista-*.whl \ |
| 72 |
&& rm /tmp/pyvista-*.whl |
| 73 |
|
| 74 |
WORKDIR /work |
| 75 |
|
| 76 |
|
| 77 |
# --------------------------------------------------------------------------- |
| 78 |
# Stage 3: jupyter runtime. PyVista with Jupyter/Trame extras, built on the |
| 79 |
# upstream jupyter/base-notebook image. The optional dependency groups come |
| 80 |
# directly from pyproject.toml so there is a single source of truth. |
| 81 |
# |
| 82 |
# The jupyter base image only publishes a single current Python tag at |
| 83 |
# quay.io/jupyter/base-notebook, so this stage is pinned to python-3.13 |
| 84 |
# regardless of the PY_VERSION build arg (which still applies to the |
| 85 |
# builder and slim stages). |
| 86 |
# --------------------------------------------------------------------------- |
| 87 |
FROM quay.io/jupyter/base-notebook:python-3.13 AS jupyter |
| 88 |
|
| 89 |
LABEL org.opencontainers.image.title="PyVista (jupyter)" |
| 90 |
LABEL org.opencontainers.image.description="PyVista with JupyterLab and Trame for interactive rendering." |
| 91 |
LABEL org.opencontainers.image.source="https://github.com/pyvista/pyvista" |
| 92 |
LABEL org.opencontainers.image.licenses="MIT" |
| 93 |
|
| 94 |
ENV JUPYTER_ENABLE_LAB=yes \ |
| 95 |
PYVISTA_TRAME_SERVER_PROXY_PREFIX=/proxy/ \ |
| 96 |
PIP_DISABLE_PIP_VERSION_CHECK=1 \ |
| 97 |
PIP_NO_CACHE_DIR=1 \ |
| 98 |
NVIDIA_VISIBLE_DEVICES=all \ |
| 99 |
NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute |
| 100 |
|
| 101 |
USER root |
| 102 |
|
| 103 |
# Runtime libraries VTK dlopens for off-screen rendering. libegl1 enables |
| 104 |
# EGL so the image uses GPU acceleration when run with the NVIDIA container |
| 105 |
# runtime, and falls back to Mesa llvmpipe software rendering on CPU-only |
| 106 |
# hosts via the libgl1/GLX path. The upstream jupyter image does not ship |
| 107 |
# these. |
| 108 |
RUN apt-get update \ |
| 109 |
&& apt-get install -y --no-install-recommends \ |
| 110 |
libopengl0 \ |
| 111 |
libgl1 \ |
| 112 |
libegl1 \ |
| 113 |
libxrender1 \ |
| 114 |
&& rm -rf /var/lib/apt/lists/* |
| 115 |
|
| 116 |
COPY --from=builder /build/dist/pyvista-*.whl /tmp/ |
| 117 |
|
| 118 |
RUN pip install "$(ls /tmp/pyvista-*.whl)[jupyter,colormaps,io]" \ |
| 119 |
&& rm /tmp/pyvista-*.whl |
| 120 |
|
| 121 |
USER ${NB_UID} |
| 122 |
WORKDIR ${HOME} |
| 123 |
|
| 124 |
EXPOSE 8888 |