Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
FROM python:3.10.11-slim-buster
# FROM python:3.10.11-slim-bookworm
# FROM python:3.11-slim-bookworm

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"]
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions start_api.sh
Original file line number Diff line number Diff line change
@@ -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