ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 下载nginx镜像 ### 下载uwsgi镜像 ### 制作项目镜像 >[info] 在uwsgi镜像的基础上制作项目镜像 假设: 项目目录为`/home/www/application/project` 日志目录为`/home/www/logs` nginx配置目录为`/home/www/nginx_conf` **启动uwsgi镜像** ``` docker run -v /home/www/application:/application -w /application/project -t -i <uwsig镜像id> /bin/bash ``` | 命令 | 解释 | | --- | --- | | -v /home/www/application:/application | 将主机的`/home/www/application`目录挂载到容器的`/application`目录 | | -w /application/project | 设定容器的工作目录为`/application/project` | **安装项目依赖** ``` pip install requirements ``` **测试项目能否正常运行** ``` python manage.py runserver 8000 ``` **退出容器** ``` exit ``` **制作项目镜像** ``` docker commit -a "作者" <容器id> project:1.0.0 ``` ### 用项目镜像启动项目 **配置uwsgi启动配置**,uwsgi.ini文件目录`/home/www/application/project/uwsgi.ini` ``` [uwsgi] uid = root gid = root chdir = /application/project module = project.wsgi callable = app py-autoreload = 1 master = true processes = 2 threads = 30 post-buffering = 65536 buffer-size = 65536 socket = 0.0.0.0:80 pidfile = /tmp/project.pid chmod-socket = 665 vacuum = true lazy-apps = true daemonize=/logs/project.log ``` **启动项目镜像** ``` docker run -v /home/www/application:/application -v /home/www/logs:/logs -v /tmp:/tmp -w /application/project --expose=80 -d project:1.0.0 sh -c "uwsgi --ini uwsgi.ini && tail -f -n 20 /logs/project.log" ``` | 命令 | 解释 | | --- | --- | | --expose=80 | 暴露容器的80端口 | | uwsgi --ini uwsgi.ini | 用uwsgi启动项目 | | tail -f -n 20 /logs/project.log | 持续输出项目日志,主要为了避免容器退出 | ### 启动nginx镜像 **查看项目容器ip地址** ``` docker inspect --format='{{.NetworkSettings.IPAddress}}' 项目容器id ``` **编辑项目的nginx配置文件**`/home/www/nginx_conf/project.conf` ``` server { listen 80; server_name localhost; access_log /logs/project_nginx.log combined; index index.html index.htm index.py; charset utf-8; client_max_body_size 75M; location / { uwsgi_pass 项目容器ip地址:80; include uwsgi_params; } } ``` **启动nginx镜像** ``` docker run -v /home/www/nginx_conf:/etc/nginx/conf.d -v /home/www/application:/application -v /home/www/logs:/logs -v /tmp:/tmp --expose=80 -p 80:80 -d nginx ```