diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a3f799e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,49 @@ +# 忽略所有 .git 目录 +.git +.github + +# 忽略所有 .DS_Store 文件(macOS) +.DS_Store + +# 忽略所有 .idea 目录(IntelliJ IDEA) +.idea + +# 忽略所有 .vscode 目录(Visual Studio Code) +.vscode + +# 忽略所有 .pyc 文件 +*.pyc + +# 忽略所有 __pycache__ 目录 +__pycache__ + +# 忽略所有 node_modules 目录 +node_modules + +# 忽略所有 log 文件 +logs/ +*.log + +# 忽略所有临时文件 +*.tmp +*.cmd + +# 忽略所有 MD 文件 +*.MD +*.md + +# 忽略特定文件 +specific_file.txt + +# 环境配置文件不存储 +.env + +# 忽略特定目录 +download/ +docker_log/ +publish/ +output/ +docs/ +data_backup/ +tools/ +test_samples/ diff --git a/Dockerfile b/Dockerfile index 6cc29aa..a2be9cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM python:3.10.11-slim-buster +# FROM python:3.10.11-slim-bookworm +# FROM python:3.11-slim-bookworm ENV DEBIAN_FRONTEND=noninteractive @@ -6,16 +8,21 @@ ENV DEBIAN_FRONTEND=noninteractive WORKDIR /app # 安装vim,如果不需要临时修改容器文件,此步骤可以删 -RUN apt-get update && \ - apt-get install -y --no-install-recommends vim && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* +# RUN apt-get update && \ +# apt-get install -y --no-install-recommends vi && \ +# apt-get clean && \ +# rm -rf /var/lib/apt/lists/* RUN set -eux; \ - pip install --no-cache-dir rapidocr_api pillow rapidocr-onnxruntime==1.3.25 -i https://mirrors.aliyun.com/pypi/simple; \ - pip uninstall -y opencv-python; \ + pip install --no-cache-dir rapidocr_api pillow rapidocr-onnxruntime==1.3.25 -i https://mirrors.aliyun.com/pypi/simple && \ + pip uninstall -y opencv-python && \ pip install --no-cache-dir opencv-python-headless -i https://mirrors.aliyun.com/pypi/simple +COPY start_api.sh /app +RUN chmod +x /app/start_api.sh + EXPOSE 9003 -CMD ["bash", "-c", "rapidocr_api -ip 0.0.0.0 -p 9003 -workers 2"] +ENV WORKERS=2 + +CMD ["bash", "start_api.sh"] diff --git a/README.md b/README.md index 6ebd796..e1b6a70 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,28 @@ with open(img_path, 'rb') as f: print(response.json()) ``` +### 构建镜像 + +构建镜像: +``` +sudo docker build -t="rapidocr_api:0.2.0" . +``` + + +启动容器: +``` +docker run -p 9003:9003 \ +-e WORKERS=16 \ +--name rapidocr_api_v2 \ +--restart always \ +-d rapidocr_api:0.2.0 +``` + +查看容器内包的版本: +``` +docker exec -it rapidocr_api_v2 bash -c "pip show rapidocr-onnxruntime && pip show rapidocr_api" +``` + ### 📚 文档 完整文档请移步:[docs](https://rapidai.github.io/RapidOCRDocs/main/install_usage/rapidocr_api/usage/) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..965d274 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + rapidocr_api: + image: rapidocr_api:${IMAGE_TAG:-latest} + container_name: markdown2png-service + ports: + - "9003:9003" + environment: + # 工作进程数量,可与CPU数量相同 + - WORKERS=4 + restart: unless-stopped + diff --git a/start_api.sh b/start_api.sh new file mode 100644 index 0000000..349b859 --- /dev/null +++ b/start_api.sh @@ -0,0 +1,16 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: start.sh +# Required-start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# chkconfig: 2345 80 90 +# Short-Description: starts the API server daemon +# Description: starts the rapidocr_api API server daemon; +### END INIT INFO + +# 从环境变量 WORKERS 读取,如果未设置或为空,则默认为 2 +WORKERS=${WORKERS:-2} + +rapidocr_api -ip 0.0.0.0 -p 9003 -workers $WORKERS