Dockerfile.scratch.oc9


Overview

This Dockerfile defines a container image based on the opencloudos/opencloudos:9.0 base image, tailored to run the ragflow application and its associated services. It sets up a Python 3.11 environment using Miniconda, installs key system dependencies including OpenMPI, Node.js, and Nginx, and prepares the container for running a complex software stack that includes web, API, and machine learning components. The container is configured to execute a custom entrypoint script to launch the application.


Detailed Explanation

Base Image and User

FROM opencloudos/opencloudos:9.0
USER root

Working Directory

WORKDIR /ragflow

System Package Installation

RUN dnf update -y && dnf install -y wget curl gcc-c++ openmpi-devel

Miniconda Installation and Python Environment Setup

RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
    bash ~/miniconda.sh -b -p /root/miniconda3 && \
    rm ~/miniconda.sh && ln -s /root/miniconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /root/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc && \
    echo "conda activate base" >> ~/.bashrc

ENV PATH /root/miniconda3/bin:$PATH

RUN conda create -y --name py11 python=3.11

ENV CONDA_DEFAULT_ENV py11
ENV CONDA_PREFIX /root/miniconda3/envs/py11
ENV PATH $CONDA_PREFIX/bin:$PATH

Node.js and Nginx Installation

RUN dnf install -y nodejs
RUN dnf install -y nginx

Adding Application Source Code

ADD ./web ./web
ADD ./api ./api
ADD ./docs ./docs
ADD ./conf ./conf
ADD ./deepdoc ./deepdoc
ADD ./rag ./rag
ADD ./requirements.txt ./requirements.txt
ADD ./agent ./agent
ADD ./graphrag ./graphrag
ADD ./plugin ./plugin

Additional MPI and Python Packages Setup

RUN dnf install -y openmpi openmpi-devel python3-openmpi
ENV C_INCLUDE_PATH /usr/include/openmpi-x86_64:$C_INCLUDE_PATH
ENV LD_LIBRARY_PATH /usr/lib64/openmpi/lib:$LD_LIBRARY_PATH
RUN rm /root/miniconda3/envs/py11/compiler_compat/ld

Frontend Build

RUN cd ./web && npm i && npm run build

Python Dependencies Installation

RUN conda run -n py11 pip install $(grep -ivE "mpi4py" ./requirements.txt) # without mpi4py==3.1.5
RUN conda run -n py11 pip install redis

Additional System Libraries and Python Packages

RUN dnf update -y && \
    dnf install -y glib2 mesa-libGL && \
    dnf clean all

RUN conda run -n py11 pip install ollama
RUN conda run -n py11 python -m nltk.downloader punkt
RUN conda run -n py11 python -m nltk.downloader wordnet

Environment Variables for Application

ENV PYTHONPATH=/ragflow/
ENV HF_ENDPOINT=https://hf-mirror.com

Configuration and Entrypoint Script

COPY docker/service_conf.yaml.template ./conf/service_conf.yaml.template
ADD docker/entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]

Important Implementation Details and Algorithms


Interaction with Other System Components


Usage Example

To build and run the container, assuming you have this Dockerfile named Dockerfile.scratch.oc9:

docker build -t ragflow-app -f Dockerfile.scratch.oc9 .
docker run -it --rm -p 80:80 ragflow-app

Visual Diagram of Workflow and Structure

flowchart TD
    A[Base Image: opencloudos:9.0] --> B[Update & Install System Packages]
    B --> C[Install Miniconda & Setup Python 3.11 Env]
    C --> D[Install Node.js & Nginx]
    D --> E[Copy Application Source Code]
    E --> F[Install OpenMPI & Set Env Variables]
    F --> G[Build Frontend (npm build)]
    G --> H[Install Python Dependencies (pip)]
    H --> I[Install Additional System Libraries & NLP Data]
    I --> J[Set Application Environment Variables]
    J --> K[Copy Config & Entrypoint Script]
    K --> L[Container Entrypoint: ./entrypoint.sh]

Summary

This Dockerfile sets up a complex environment to run the ragflow application, combining system-level components, a Python 3.11 Conda environment, Node.js frontend build steps, and MPI support. It carefully manages dependencies and environment variables to support high-performance distributed computing and web serving, encapsulated with an entrypoint script to start the application services.

The file is a crucial part of the deployment pipeline, enabling consistent, reproducible builds of the ragflow service stack optimized for OpenCloudOS 9.0 environments.