记录一个任务:将我的代码部署到docker中去
任务: 把代码部署上去,部署到我的docker中去
步骤分解:
1.本地跑通代码
2.生成pip的requirements.txt文件
pip install pipreqs
pipreqs . --encoding=utf8 --force
验证生成的requirements.txt 是否正确
创建一个新的conda环境,然后复制过去,测试环境是否可行
这里需要配置清华的镜像源,否则装不上哦
conda create -n docker_a python=3.12.4
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
3.启动虚拟机
4.启动docker
systemctl start docker
systemctl status docker
5.将本地的文件传递到linux机器上面
docker images
docker ps
docker run -itd imageID
docker ps
docker exec -it continerID
我这里使用的是ubuntu的容器,如果你没有 则 docker pull ubuntu
6.将linux机器使用docker cp 传递到docker容器上面
docker cp linux位置 容器id:容器的位置
7.docker容器安装 miniconda,
发现这个docker中的ubuntu什么都没有安装啊
我们应该怎么做:1.安装wget 2.安装miniconda 3.安装requirements.txt 4.执行命令启动python的app.py
sudo apt-get update 更新软件包
sudo apt-get install build-essential 安装系统编译工具
sudo apt-get install wget 安装wget
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
然后一直输入yes就行了
需要设置环境变量
vi ~/.bashrc
我的miniconda安装在这里了 /root/miniconda3
export PATH="/root/miniconda3/bin:$PATH"
source ~/.bashrc
然后conda就可以使用了
8.创建新的环境,并下载requirements.txt
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda create -n docker_a python=3.12.4 -c https://pypi.tuna.tsinghua.edu.cn/simple
conda activte XXX
pip install -r ./requirements.txt
9.启动项目
python app.py
http://127.0.0.1:5000/email_submit
10.提交镜像
docker export 容器ID > xxx.tar
docker import xxx.tar xxx:tag
或者使用指令:
docker commit 容器ID imageID
10.发现外部无法访问,于是更改启动的指令
docker run -dit --privileged -p5000:5000 --name docker_a_continer docker_a:latest /bin/bash
docker exec -it container的名字 /bin/bash
python app.py
但是我现在要后台运行这个命令,所以使用下面的命令
nohup python app.py > output.log &
下面是我的项目哦,我的模型, 是一个验证输入是垃圾广告还是正常对话的项目。你得用F12看请求和响应哦,笔下留情
链接:https://pan.baidu.com/s/1JZ5S4RvRf4hnYeiYLRUXfQ?pwd=6ro7
提取码:6ro7