Docker deployment

Biom3d provides Docker images, and this section will describe their maintenance and usage in more detail. They are created by template.dockerfile here :

 1# syntax=docker/dockerfile:1.4
 2
 3ARG BASE_IMAGE=ubuntu:22.04
 4FROM ${BASE_IMAGE}
 5
 6ARG TARGET=cpu
 7ARG PYTHON_VERSION=3.11
 8ARG OMERO_VERSION=5.21.0
 9ARG TESTED=1
10
11ENV TESTED=${TESTED}
12ENV DEBIAN_FRONTEND=noninteractive
13ENV PYTHON_BIN=python${PYTHON_VERSION}
14
15# Install system dependencies
16RUN apt-get update && apt-get install -y \
17    software-properties-common \
18    curl \
19    git \
20    && add-apt-repository ppa:deadsnakes/ppa \
21    && apt-get update && apt-get install -y \
22    python${PYTHON_VERSION} \
23    python${PYTHON_VERSION}-distutils \
24    python${PYTHON_VERSION}-venv \
25    python${PYTHON_VERSION}-tk \
26    python3-pip \
27    && apt-get clean && rm -rf /var/lib/apt/lists/* \
28    && mkdir -p /workspace && chmod 777 /workspace \
29    && mkdir -p /Biom3d && chmod 777 //Biom3d \
30    #
31    # Upgrade pip & install OMERO
32    && ${PYTHON_BIN} -m pip install --upgrade pip setuptools wheel && \
33    ${PYTHON_BIN} -m pip install \
34    https://github.com/glencoesoftware/zeroc-ice-py-linux-x86_64/releases/download/20240202/zeroc_ice-3.6.5-cp311-cp311-manylinux_2_28_x86_64.whl \
35    omero-py==${OMERO_VERSION}\
36    && ${PYTHON_BIN} -m pip install --no-cache-dir --no-deps ezomero 
37    
38# Clone project
39COPY . /Biom3d
40WORKDIR /Biom3d
41
42# Copy entrypoint
43RUN chmod +x /Biom3d/deployment/dockerfiles/entrypoint.sh \
44    #
45    # Install biom3d
46    && ${PYTHON_BIN} -m pip install . \
47    #
48    # Conditional: Install torch or fix symlink depending on CPU or GPU
49    && if [ "$TARGET" = "cpu" ]; then \
50        ${PYTHON_BIN} -m pip install torch --index-url https://download.pytorch.org/whl/cpu ; \
51        elif [ "$TARGET" = "gpu" ]; then \
52        ln -s /opt/conda/lib/libnvrtc.so.11.2 /opt/conda/lib/libnvrtc.so || true ; \
53        fi
54
55WORKDIR /workspace
56ENTRYPOINT ["/Biom3d/deployment/dockerfiles/entrypoint.sh"]

Available images are Linux only, Windows ones aren’t on our backlog.

Build arguments

The following build arguments are supported :

  • BASE_IMAGE : The base image used to build Biom3d images. By default, it’s ubuntu:22.04. Our images aiming for GPU (Nvidia) uses official PyTorch images.

  • TARGET : Either cpu or gpu, it ils only used in our CI/CD that use it to automatically create the tag and create a CUDA symlink in the image for usage sake.

  • PYTHON_VERSION : Python version used in the image, we recommend the 3.11 as some Biom3d dependencies aren’t all compatible with all version.

  • OMERO_VERSION : The omero-py package version. For now only the 5.21.0 has been tested.

  • TESTED : Indicate the image stability

    • 1 (default), tested and stable

    • 0, the entry point will display a warning message. It is used for images that should work (theoretically) but couldn’t be tested extensively.

Installing dependencies

Biom3d automatically install its dependencies with :

pip install biom3d

But some optionnal dependencies require additional steps :

  • omero-py : It require zeroc-ice<3.7 difficult to find for Linux, prebuild found here. Then we can install omero-py. Always install zeroc-ice before omero-py or it will try to compile it from C++.

  • ezomero must be installed with --no-deps or it will downgrade numpy to an incompatible version and break everything. Other dependencies use numpy 2.x that is marked as not compatible with ezomero but the 2.2.6 hasn’t created a problem. Expect a incompatibility warning that you can ignore. As it is installed with --no-deps, always install it after omero-py.

  • tkinter comes with system dependencies but is easily installed with apt install python${PYTHON_VERSION}-tk.

Entrypoint

The default entrypoint is dockerfile` here :

1#!/bin/sh
2submodule=$1
3shift
4if [ "$TESTED" = 0 ]; then
5    echo "[WARNING] This image hasn't been totally tested. If any problem is encountered, please open an issue at https://github.com/GuillaumeMougeot/biom3d"
6fi
7
8exec python3.11 -m biom3d."$submodule" "$@"

It displays a warning if needed and launches Biom3d, waiting for a submodule and its arguments. This script is intentionally simple — feel free to replace it with a custom entrypoint suited to your use case.

Other specificities

The WORKDIR is set on /workspace which mean that dataset volume should be attached there. If you want a more granular approach (for example that preprocess_train doesn’t create preprocessed data folder there) you can do it by modifying the ENTRYPOINT script or WORKDIR (or both).

The line ln -s /opt/conda/lib/libnvrtc.so.11.2 /opt/conda/lib/libnvrtc.so || true is here to do a symlink so that torch find the cuda drivers.