1.新建uvicorn文件
(1)安装uvicorn插件
pip install uvicorn
(2)新建main.py文件
from uvicorn.server import Config, Server
from server.asgi import application
config = Config(app=application, host="0.0.0.0", port=8000, loop="asyncio", log_level="info")
server = Server(config)
server.run()
2.上传django工程
# 1.进入工程目录
[root@localhost ~]# cd /mydq
[root@localhost mydq]# ls
server server.zip
# 2.运行一个Python 3.10的容器
[root@localhost server]# docker run -it -d python:3.10
08bf74577ae38e40301a16d5e7491384dca6a31e35fbdf65fddddac03f9616fe
[root@localhost server]# docker ps
CONTAINER ID IMAGE COMMAND CREATED PORTS NAMES
08bf74577ae3 python:3.10 "python3" 5 seconds ago upbeat_jennings
b76ad00c7d5e my_vue "/docker-entrypoint.…" 2 days ago 0.0.0.0:88->80/tcp, :::88->80/tcp nice_pascal
# 3.把工程文件server拷贝到08…容器内
[root@localhost mydq]# docker cp server 08:/
Successfully copied 533MB to 08:/
# 4.进入容器
[root@localhost mydq]# docker exec -it 08 /bin/bash
root@08bf74577ae3:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin server srv sys tmp usr var
root@08bf74577ae3:/# cd server
root@08bf74577ae3:/server# ls
__pycache__ app_baseinfo app_roadway app_theroym coalbasic_data.db main.py others requirements.txt
app_3dwork app_pressure app_sysother app_userinfo dd manage.py readme.md server
# 利用清华镜像源,安装依赖
root@08bf74577ae3:/server# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
3.安装pyinstaller,进行打包
# 利用清华镜像源,安装pyinstaller插件、uvicorn插件
root@08bf74577ae3:/server# pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
root@08bf74577ae3:/server# pip install uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
# 根据main.py 进行打包
root@08bf74577ae3:/server# pyinstaller -F main.py
158 INFO: PyInstaller: 6.3.0
158 INFO: Python: 3.10.1
160 INFO: Platform: Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.31
160 INFO: wrote /code/main.spec
4.运行工程
root@08bf74577ae3:/server# ls
__pycache__ app_baseinfo app_roadway app_theroym build dd main.py manage.py readme.md server
app_3dwork app_pressure app_sysother app_userinfo coalbasic_data.db dist main.spec others requirements.txt
root@08bf74577ae3:/server# cd dist
root@08bf74577ae3:/server/dist# ls
main
root@08bf74577ae3:/server/dist# ./main
Traceback (most recent call last):
File "main.py", line 8, in <module>
ModuleNotFoundError: No module named 'uvicorn'
[2352] Failed to execute script 'main' due to unhandled exception
5.未完
尝试安装"vi"编辑器,使用以下命令:
apt-get update
apt-get install vim
标签:main,app,py,django,linux,server,root,08bf74577ae3,打包
From: https://www.cnblogs.com/DQ-MINE/p/17995250