1、安装docker和docker-compose
2、配置Dockerfile
FROM python:3.8
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN rm -rf /ocr/*
# Allows docker to cache installed dependencies between builds
COPY ./requirements /requirements
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --upgrade pip \
&& pip install -r /requirements/local.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
# Adds our application code to the image
COPY . /ocr
WORKDIR /ocr
EXPOSE 8000
3、配置docker-compose.yml
version: '3'
services:
ocr_test:
# platform: linux/amd64
build:
context: .
dockerfile: compose/local/flask/Dockerfile
command: >
bash -c "python -m wsgi.py"
volumes:
- ./:/ocr
ports:
- "8000:8000"
4、项目目录结构
5、打包镜像
docker-compose build
6、启动项目
docker-compose up
因为使用paddleocr这个包,每次启动都要检查参数,使用uwsgi、uvicorn、gunicorn等方式启动都会失败,目前还没有解决方案,现在只能用python直接启动