CONOPS imaging Dockerfile
Generated from docs/examples/conops-imaging/Dockerfile. Do not edit directly.
FROM registry.dphi.space/base/pytorch:25.08-py3
# Non-secret Build Arguments only. The Devpi simple index is the platform's internal
# mirror; --isolated ignores any pip configuration baked into the base image, so a cache
# miss fails the build instead of silently reaching a public index. Do not add a PyPI URL
# or an extra index here.
ARG DEVPI_SIMPLE_URL
ARG ULTRALYTICS_PACKAGE=ultralytics
USER root
# Keep the externally managed base interpreter intact while exposing its preinstalled
# torch package to the application environment.
# ultralytics depends on `opencv-python`, whose native cv2 links against libxcb and the
# rest of the X11 stack. This base image is headless and carries none of it, so importing
# ultralytics dies with `ImportError: libxcb.so.1`. `opencv-python-headless` is the same
# library built without the GUI backends and provides the same `cv2` module, so swapping
# it in after the resolver has had its way satisfies ultralytics without dragging a
# display stack into a container that has no display. Installing it first would not work:
# the dependency is on the `opencv-python` NAME, so pip would fetch that one anyway.
RUN python -m venv --system-site-packages /opt/conops-venv \
&& /opt/conops-venv/bin/pip install --isolated --no-cache-dir \
--index-url "${DEVPI_SIMPLE_URL}" \
--trusted-host devpi.artifacts \
"${ULTRALYTICS_PACKAGE}" \
&& /opt/conops-venv/bin/pip uninstall -y opencv-python opencv-contrib-python \
&& /opt/conops-venv/bin/pip install --isolated --no-cache-dir \
--index-url "${DEVPI_SIMPLE_URL}" \
--trusted-host devpi.artifacts \
opencv-python-headless \
&& /opt/conops-venv/bin/pip uninstall -y numpy
ENV PATH="/opt/conops-venv/bin:${PATH}"
# Generated Workload Pods run as UID 1000 with no writable home, and both libraries want
# a config directory on first import. Set it before the check below, which imports them.
ENV YOLO_CONFIG_DIR=/tmp/ultralytics
ENV MPLCONFIGDIR=/tmp/matplotlib
# Fail the build if the vendor torch was replaced anyway. --system-site-packages only
# makes that build VISIBLE to the venv; it does not stop a resolver that judged
# `torch>=1.8.0` unsatisfied -- the base image's version carries a pre-release suffix,
# and pip excludes pre-releases when testing a specifier -- from installing a stock
# wheel over it inside the venv. Left unchecked that is silent: the image builds green,
# the GPU schedules, and the Run is the first thing to discover it holds a CPU wheel.
# ... and the same for numpy, which is the OTHER half of the same trap and was not
# covered. ultralytics and opencv both depend on numpy, so the resolver installs a current
# one (2.5.2) into the venv, where it shadows the 1.26.4 the vendored torch was compiled
# against. torch's C extension then refuses it and every `torch.from_numpy` -- which is how
# ultralytics hands an image to the model -- dies with `RuntimeError: Numpy is not
# available`. That is a RUN-time failure, minutes after a green build, in a GPU Job that
# has already waited out an orbital pass. The uninstall above drops the venv copy so the
# base image's numpy is used through --system-site-packages, and this asserts it stuck.
RUN python -c "\
import sys, numpy, torch, ultralytics; \
shadowed = [name for name, module in (('torch', torch), ('numpy', numpy)) \
if module.__file__.startswith('/opt/conops-venv')]; \
sys.exit('venv shadowed the base image ' + ', '.join(shadowed)) if shadowed else \
print('torch', torch.__version__, '/ numpy', numpy.__version__, 'from the base image')"
# Prove the pairing actually works rather than merely that both import: the failure this
# guards is a torch that cannot accept an array from the numpy sitting next to it.
RUN python -c "\
import numpy, torch; \
torch.from_numpy(numpy.zeros((2, 2), dtype=numpy.float32)); \
print('torch.from_numpy works against numpy', numpy.__version__)"
WORKDIR /app
# Both paths are relative to the build context, which is the `conops-imaging/` directory
# IN THE TENANT'S VOLUME (see image-build.yaml `contextPath`), not this source directory
# on the tenant volume rather than its root.
COPY conops_imaging.py /app/conops_imaging.py
COPY mobile_sam.pt /app/mobile_sam.pt
USER 1000
CMD ["python", "/app/conops_imaging.py"]