Create Juyterlab with getFEM usage in Docker container

Hello community,
I need to setup a Docker container with JupyterLab and getFEM library.
I created this Dockerfile but I would upgrade the original python version (3.8) provided by the image base with the latest 3.12 version.
Any help please ?


FROM getfemdoc/getfem:stable

ARG NB_USER=jovyan
ARG NB_UID=1000

ENV DEBIAN_FRONTEND=noninteractive \
    LANG=C.UTF-8 \
    TERM=xterm \
    USER=${NB_USER} \
    HOME=/home/${NB_USER} \
    PYTHONPATH="/usr/lib/python3.12/dist-packages"

RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    python3-venv \ 
    && rm -rf /var/lib/apt/lists/*

# ensure that python3 is correctly linked to python    
RUN ln -s /usr/bin/python3 /usr/bin/python    

# install the jupyter lab
RUN pip install --no-cache --upgrade pip && \
    pip install --no-cache-dir \
    jupyterlab \
    numpy \
    pandas \
    matplotlib \
    sympy \
    gmsh \
    scipy \
    import-ipynb \
    ipywidgets \
    opencv-python

# create user with a home directory
RUN adduser --disabled-password \
    --gecos "Default user" \
    --uid ${NB_UID} \
    ${NB_USER}

WORKDIR ${HOME}
USER root
COPY . ${HOME}
RUN pip3 install -r requirements.txt
RUN chown -R ${NB_USER} ${HOME}
USER ${USER}

# Expose JupyterLab port
EXPOSE 8888

# Start JupyterLab
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root", "--NotebookApp.token=''"]

I think this is the Dockerfile for the base image

You could try rebuilding that? If any fixes are needed you could see if upstream are willing to accept them, so they can publish an official updated Python image.

I have reorganized and rebuilt the original Dockerfile of getFEM, then I have used the image created as base of my Dockerfile to create Jupyterlab.
Thanks also to AI it work fine with ubuntu:22.04 and Python 3.10.
Here my final (and hard) work.

# Dockerfile.getfem
FROM ubuntu:22.04

SHELL ["/bin/bash", "-c"]

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
    LANG=C.UTF-8 \
    TERM=xterm \
    TAG_NAME=master

# Set working directory
WORKDIR /work

# Install all dependencies in a single layer
RUN apt-get update && apt-get install -y --no-install-recommends \
    # Build tools
    automake \
    g++ \
    git \
    libtool \
    make \
    # Libraries
    libqd-dev \
    libqhull-dev \
    libmumps-seq-dev \
    liblapack-dev \
    libopenblas-dev \
    libpython3-dev \
    # Documentation tools
    imagemagick \
    fig2dev \
    texlive \
    xzdec \
    fig2ps \
    gv \
    # Python tools
    python3-pip \
    python3-venv \
    # Basic requirements
    ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Set up virtual environment and install getfem
RUN python3 -m venv /venv && \
    git clone https://git.savannah.nongnu.org/git/getfem.git && \
    cd getfem && \
    source /venv/bin/activate && \
    pip install --no-cache --upgrade pip && \
    pip install --no-cache-dir setuptools && \
    pip install -r requirements.txt && \
    git checkout $TAG_NAME && \
    bash autogen.sh && \
    ./configure --prefix=/venv --with-pic && \
    make -j$(nproc) && \
    make -j$(nproc) check && \
    make install && \
    cd interface && \
    make install && \
    deactivate && \
    cd / && \
    rm -rf getfem && \
    echo "Getfem installed at /venv"

# Use non-root user for better security
USER 1000
# Dockerfile Jupyterlab
FROM mygetfem:latest

ARG NB_USER=jovyan
ARG NB_UID=1010

USER root

ENV DEBIAN_FRONTEND=noninteractive \
    LANG=C.UTF-8 \
    TERM=xterm \
    PATH="/venv/bin:$PATH" \
    HOME=/home/${NB_USER} \
    SHELL=/bin/bash \
    USER=${NB_USER} \
    PYTHONPATH="/venv/lib/python3.12/site-packages"

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        libgl1 \
        libglu1-mesa \
        libxcursor1 \
        libxft2 \
        xvfb && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    useradd -m -s /bin/bash -u ${NB_UID} ${NB_USER}

COPY config/ ${HOME}/.jupyter/
COPY requirements* ./

RUN /venv/bin/pip install --no-cache-dir -r requirements.txt && \
    /venv/bin/pip install --upgrade gmsh && \
    chown -R ${NB_USER}:${NB_USER} ${HOME} && \
    chmod -R 700 ${HOME}

# Disable the news feed popup
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"


USER ${NB_USER}
WORKDIR ${HOME}

EXPOSE 8888

CMD ["/venv/bin/jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]