1、安装python3

cd /data
rz Python-3.12.0.tar.xz
tar -xvf Python-3.12.0.tar.xz
cd Python-3.12.0
./configure
make && make install

yum install zlib zlib
yum install zlib zlib-devel

pip install virtualenv

pip install Flask
mkdir /data/www_python3
cd /data/www_python3

2、卸载系统之前可能安装的 docker(防止冲突)
卸载系统之前可能安装的 docker(防止版本不一致,发生冲突)

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

3、安装 Docker-CE 基本环境

安装必须的依赖

yum install -y yum-utils device-mapper-persistent-data lvm2

设置 docker repo 的 yum 位置

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
或者 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装 docker,以及 docker-cli

yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

4、启动 docker

#启动docker
systemctl start docker
#查看docker服务状态 running 就是启动成功
systemctl status docker

5、设置 docker 开机自启

systemctl enable docker

6、测试 docker 常用命令
docker命令官方文档 https://docs.docker.com/engine/reference/commandline/docker/

7、docker安装mysql redis等详见
https://blog.csdn.net/qq_58141314/article/details/131020932

8、创建index.py、marvimage.sh、crontab定时任务
#################################################################
/data/www_python3/index.py:使用python执行系统命令、相关环境。服务
/home/marvimage.sh:检测index.py(服务)是否在运行中,没有运行服务,则启动服务
crontab:定时任务,每隔时间执行sh脚本文件
*/2 * * * * /bin/sh /home/marvimage.sh >> /data/logs/marvimage.log&
#################################################################
import flask, json
from flask import request
import os
import time

server = flask.Flask(__name__)

@server.route('/image', methods=['post'])
def getSmiles():
img = request.files['file']
# print('file',img)
Sdate = time.strftime("%Y%m%d", time.localtime())
volume = '/data/www/www.chemenu.com/public/assets/marvin_image/'+Sdate
if not os.path.exists(volume):
os.makedirs(volume)

filename = time.strftime("%H%M%S", time.localtime())+'.png'
weburl = '/assets/marvin_image/'+Sdate+'/'+filename
img.save(volume+'/'+filename)

os.system('docker container run --volume '+volume+':/input berlinguyinca/osra osra --write /input/'+filename+'.smi /input/'+filename)
f = open(volume+'/'+filename+'.smi', 'r')
Sread = str(f.read())
f.close()
return weburl + '[#^^#]' + Sread


@server.route('/')
def index_page():
return 'this_is_a_first_page'

if __name__ == '__main__':
server.run(debug=False, port=20000, host='0.0.0.0')
#################################################################
shell脚本(marvimage.sh),检测index.py是否在运行
#################################################################
#!/bin/sh

curl http://127.0.0.1:20000 > /home/marvimg_test.txt
txt=`cat /home/marvimg_test.txt | grep this_is_a_first_page`
if [ ${#txt} -lt 10 ]
then
/usr/local/bin/python3 /data/www_python3/index.py
fi
#################################################################
或者
#################################################################
#!/bin/sh

txt=`ps -ef | grep 'python3 /data/www_python3/index.py' | wc -l`
if [ $txt -lt 2 ]
then
/usr/local/bin/python3 /data/www_python3/index.py
fi
#################################################################


docker pull berlinguyinca/osra

docker run -it berlinguyinca/osra --version

docker container run --volume /data/www_python3:/input berlinguyinca/osra osra /input/3333.png

python3 index.py