root@tzktzk1-Lenovo-Gaming:/home/tzktzk1/software/autotpsite# pwd
/home/tzktzk1/software/autotpsite
root@tzktzk1-Lenovo-Gaming:/home/tzktzk1/software/autotpsite# ls
auto_deploy.sh autotpsite demo dist Dockerfile manage.py requirements.txt sqtp utils uwsgi8081.pid uwsgi.ini uwsgi_server.log
root@tzktzk1-Lenovo-Gaming:/home/tzktzk1/software/autotpsite# docker build -t autotp:v1 . # 结尾一定要加空格再加点
[+] Building 42.9s (8/8) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 157B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3.9 0.0s
=> [1/3] FROM docker.io/library/python:3.9 0.0s
=> [internal] load build context 0.4s
=> => transferring context: 40.66MB 0.4s
=> [2/3] COPY . /opt 0.6s
=> [3/3] RUN cd opt/ && sh auto_deploy.sh 40.1s
=> exporting to image 1.7s
=> => exporting layers 1.7s
=> => writing image sha256:0881eba8b91ab232ce89116d749840c3b74c3e4b89b21235d531d7a5519a602e 0.0s
=> => naming to docker.io/library/autotp:v1 0.0s
root@tzktzk1-Lenovo-Gaming:/home/tzktzk1/software/autotpsite#
此时我们启动容器的命令也可以很简单,由于镜像内包括了运行所需的库和代码文件,所以这里就不需
要映射目录了
docker run -it -d --rm --name autotpenv autotp:v1
vim auto_deploy.sh
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn && pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
vim Dockerfile
FROM python:3.9
COPY . /opt
RUN cd opt/ && sh auto_deploy.sh
CMD cd opt/ && uwsgi uwsgi.ini && tail -f uwsgi_server.log
vim requirements.txt
pip==23.3.1
setuptools==69.0.2
wheel==0.41.3
Django==4.2.7
djangorestframework==3.14.0
drf-yasg==1.21.7
httprunner==3.1.6
mysqlclient==2.2.1
MarkupSafe==2.0.1
jira==3.5.2
vim uwsgi.ini
[uwsgi]
chdir = ./
# 项目根目录
module = autotpsite.wsgi:application
# 指定wsgi模块下的application对象
#http = 0.0.0.0:8081
http-socket = 0.0.0.0:8081
# 对本机8081端口提供服务
master = true
# 主进程
# 以上4个是核心配置项
#vhost = true
# 多站模式
#no-site = true
# 多站模式时不设置入口模块和文件
#workers = 2
# 子进程数
#reload-mercy = 10
#vacuum = true
# 退出、重启时清理文件
#max-requests = 1000
#limit-as = 512
#buffer-size = 30000
pidfile = uwsgi8081.pid
# pid文件,用于下脚本启动、停止该进程
daemonize = uwsgi_server.log
# 日志文件
disable-logging = true
# 不记录正常信息,只记录错误信息