2.o / Dockerfile
admin08077's picture
Update Dockerfile
976e75b verified
# Use an official Ubuntu base image
FROM ubuntu:22.04
# Set non-interactive mode for apt
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
software-properties-common \
build-essential \
cmake \
g++ \
git \
wget \
curl \
pkg-config \
python3.10 \
python3.10-venv \
python3-pip \
python3-dev \
libboost-all-dev \
libhdf5-dev \
libpugixml-dev \
libspdlog-dev \
libopenmpi-dev \
libparmetis-dev \
libscotch-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PETSc dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libhypre-dev \
libmumps-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Create Python virtual environment
RUN python3.10 -m venv /opt/venv
# Activate virtual environment
ENV PATH="/opt/venv/bin:$PATH"
# Upgrade pip and install Python packages
RUN pip install --upgrade pip
# Install mpi4py and additional Python packages
RUN pip install numpy mpi4py cffi scikit-build-core[pyproject] petsc4py slepc4py
# Clone and build Basix (required by dolfinx)
RUN git clone --branch main https://github.com/FEniCS/basix.git /tmp/basix && \
mkdir -p /tmp/basix/build && cd /tmp/basix/build && \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
make -j$(nproc) && make install
# Clone and build UFCx (required by dolfinx)
RUN git clone --branch main https://github.com/FEniCS/ufcx.git /tmp/ufcx && \
mkdir -p /tmp/ufcx/build && cd /tmp/ufcx/build && \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
make -j$(nproc) && make install
# Clone and build dolfinx (C++ core and Python bindings)
RUN git clone --branch main https://github.com/FEniCS/dolfinx.git /tmp/dolfinx && \
mkdir -p /tmp/dolfinx/cpp/build && cd /tmp/dolfinx/cpp/build && \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
make -j$(nproc) && make install && \
cd /tmp/dolfinx/python && \
pip install -r build-requirements.txt && \
pip install --check-build-dependencies --no-build-isolation .
# Verify dolfinx installation
RUN python -c "import dolfinx; print('dolfinx version:', dolfinx.__version__)"
# Clean up build files
RUN rm -rf /tmp/basix /tmp/ufcx /tmp/dolfinx
# Install Gradio and other Python dependencies
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN pip install --no-cache-dir gradio[oauth]==5.9.1 "uvicorn>=0.14.0" spaces matplotlib pandas
# Freeze installed Python packages (optional)
RUN pip freeze > /tmp/freeze.txt
# Set application working directory
WORKDIR /home/user/app
# Copy application files
COPY . /home/user/app
# Expose the Gradio app port
EXPOSE 7860
# Set default command to run the app
CMD ["python", "app.py"]