Skip to content

Docker 安装 MinerU

MinerU是一款将PDF转化为机器可读格式的工具(如markdown、json),可以很方便地抽取为任意格式。


环境说明

  • Ubuntu 24.04.3 LTS
  • Docker 29.1.2
  • MinerU 2.6.6(根据自己需求调整版本)

克隆仓库

克隆仓库,或从 Releases 中下载指定版本 source 包。

shell
git clone https://github.com/opendatalab/MinerU.git

构建镜像

进入 MinerU/docker/china 目录下,编辑 Dockerfile 文件,固定 mineru[core] 版本为 2.6.6。

MinerU/docker/china/Dockerfile
dockerfile
# Use DaoCloud mirrored vllm image for China region for gpu with Ampere architecture and above (Compute Capability>=8.0)
# Compute Capability version query (https://developer.nvidia.com/cuda-gpus)
FROM docker.m.daocloud.io/vllm/vllm-openai:v0.10.1.1

# Use DaoCloud mirrored vllm image for China region for gpu with Turing architecture and below (Compute Capability<8.0)
# FROM docker.m.daocloud.io/vllm/vllm-openai:v0.10.2

# Install libgl for opencv support & Noto fonts for Chinese characters
RUN apt-get update && \
    apt-get install -y \
        fonts-noto-core \
        fonts-noto-cjk \
        fontconfig \
        libgl1 && \
    fc-cache -fv && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Install mineru 2.6.6
RUN python3 -m pip install 'mineru[core]==2.6.6' -i https://mirrors.aliyun.com/pypi/simple --break-system-packages && \
    python3 -m pip cache purge

# Install mineru latest
#RUN python3 -m pip install -U 'mineru[core]' -i https://mirrors.aliyun.com/pypi/simple --break-system-packages && \
#    python3 -m pip cache purge

# Download models and update the configuration file
RUN /bin/bash -c "mineru-models-download -s modelscope -m all"

# Set the entry point to activate the virtual environment and run the command line tool
ENTRYPOINT ["/bin/bash", "-c", "export MINERU_MODEL_SOURCE=local && exec \"$@\"", "--"]

构建镜像,需要下载几十 GB 资源。我们公司网络一般,耗费了 5 个半小时。

构建镜像
shell
cd MinerU/docker/china
docker build -t mineru:2.6.6 .

运行容器

使用官方提供的 compose.yml 进行启动。我们只需要使用 web api,所以去除了 openai-server、gradio。由于没有显卡,所以使用 pipline cpu 模式运行,把 gpu 配置也去除了。

MinerU/docker/compose.yml
yaml
services:
  mineru-api:
    image: mineru:2.6.6
    container_name: mineru-api
    restart: always
    profiles: ["api"]
    ports:
      - 8000:8000
    environment:
      MINERU_MODEL_SOURCE: local
    entrypoint: mineru-api
    command:
      --host 0.0.0.0
      --port 8000
    ulimits:
      memlock: -1
      stack: 67108864
    ipc: host

运行容器。

运行容器
shell
docker compose -f compose.yaml --profile api up -d
docker compose logs -f mineru-api

访问接口文档

在浏览器中访问 http://<server_ip>:8000/docs 查看API文档。

参考资料

  1. 使用docker部署Mineru - MinerU文档:https://opendatalab.github.io/MinerU/zh/quick_start/docker_deployment/