-
书写 gunicron 配置文件
- dash-gunicron.py
- public-gunicron.py
- 使用其配置请求记录, 那么nginx 可以不写请求日志
- 书写错误日志
dash-gunicron.py
workers=8 # 进程数 threads = 2 # 工作者的线程数 bind = '0.0.0.0:5558' daemon = 'false' # 使用suppervisor 管理, 暂时使用nohup worker_class = "gevent" # 并发 worker_connections = 2000 pidfile = '/var/run/gunicorn.pid' # 设置进程文件目录 accesslog = '/var/log/gunicorn/gun_dash_acess.log' errorlog = '/var/log/gunicorn/gun_dash_error.log' # 设置日志记录水平 loglevel = 'warning'
public-gunicron.py
workers=8 # 进程数 threads = 2 # 工作者的线程数 bind = '0.0.0.0:5555' daemon = 'false' # 使用suppervisor 管理, 暂时使用nohup worker_class = "gevent" # 并发 worker_connections = 2000 pidfile = '/var/run/gunicorn.pid' # 设置进程文件目录 accesslog = '/var/log/gunicorn/gun_public_acess.log' errorlog = '/var/log/gunicorn/gun_public_error.log' # 设置日志记录水平 loglevel = 'warning'
-
书写Dockerfile
我们使用nginx做代理
下载配置文件
做好在执行的时候配置好nginx 配置
FROM python:3.6.9
WORKDIR ~/docker/python-web
COPY requirments.txt ./
# 从指定源下载
RUN pip install -r requirments.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN mkdir -p /var/log/gunicorn
RUN touch /var/log/gunicorn/gun_public_access.log
RUN touch /var/log/gunicorn/gun_public_error.log
RUN touch /var/log/gunicorn/gun_dash_access.log
RUN touch /var/log/gunicorn/gun_dash_error.log
# 将项目拷贝到容器工作目录下
COPY . .
CMD ["nohup", "gunicorn", "app:dash()", "-c", "dash-gunicorn.py"], ">", "/var/log/web/dash.out"
CMD ["nohup", "gunicorn", "app:public()", "-c", "dash-gunicorn.py"], ">", "/var/log/web/public.out"
3.打包镜像
docker image build -t ceshi .
4.启动docker
docker-run.sh
docker run -d --name ceshi -p 8000:5558 -p 8080:5555 ceshi
5.进入docker 空间
docker exec -it ceshi /bin/bash
如果需要使用nginx 则在外部创建nginx 进行代理, 或者在容器内代理都是可以的