Docker内启动gunicorn失败,django项目

[2021-09-28 20:41:48 +0800] [1765] [INFO] Worker exiting (pid: 1765)
[2021-09-28 12:41:48 +0000] [1792] [INFO] Booting worker with pid: 1792
[2021-09-28 12:41:48 +0000] [1793] [INFO] Booting worker with pid: 1793
[2021-09-28 20:41:48 +0800] [1774] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
    super().init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 142, in init_process
    self.run()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 195, in run
    self.notify()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 75, in notify
    self.tmp.notify()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/workertmp.py", line 46, in notify
    os.fchmod(self._tmp.fileno(), self.spinner)
FileNotFoundError: [Errno 2] No such file or directory

同样的配置在mac开发机上启动没问题,在docker下就有问题;

配置文件如下

# -*- coding: utf-8 -*-
import multiprocessing
from pathlib import Path

BASE_DIR = Path(__file__).resolve(strict=True).parent

debug = False

# ============================================================
# gunicorn要切换到的目的工作目录
# ============================================================

chdir = str(BASE_DIR)

# ============================================================
# server socket相关
# ============================================================

# 指定绑定的ip和端口
bind = "0.0.0.0:8080"

# 服务器中排队等待的最大连接数,建议值64-2048,超过2048时client连接会得到一个error
backlog = 2048

# ============================================================
# 调试相关
# ============================================================

# 当代码有修改时,自动重启workers,适用于开发环境
reload = False

# 以守护进程形式来运行Gunicorn进程,其实就是将这个服务放到后台去运行
daemon = False

# ============================================================
# worker进程相关
# ============================================================

# 用于处理工作的进程数
workers = multiprocessing.cpu_count() * 2 + 1

# worker进程的工作方式,有sync、eventlet、gevent、tornado、gthread, 默认是sync,
# django使用gevent容易造成阻塞, 使用gthread的方式好一些
worker_class = 'gthread'

# 指定每个工作进程开启的线程数
threads = multiprocessing.cpu_count() * 2

# 访问超时时间
timeout = 30

# 接收到restart信号后,worker可以在graceful_timeout时间内,继续处理完当前requests
graceful_timeout = 60

# server端保持连接时间
keepalive = 30

# ============================================================
# 日志相关
# ============================================================

"""日志文件格式,其每个选项的含义如下:
h          remote address
l          '-'
u          currently '-', may be user name in future releases
t          date of the request
r          status line (e.g. ``GET / HTTP/1.1``)
s          status
b          response length or '-'
f          referer
a          user agent
T          request time in seconds
D          request time in microseconds
L          request time in decimal seconds
p          process ID
"""
access_log_format = '%(t)s %(h)s "%(r)s" %(s)s %(b)s "%(f)s" "%(L)s"'

errorlog = '/tmp/gunicorn.error.log' #发生错误时log的路径

accesslog = '/tmp/gunicorn.access.log' #正常时的log路径

# 错误日志输出等级,访问日志的输出等级无法设置
loglevel = "info"

# ============================================================
# 进程名相关
# ============================================================

# 设置进程名称,默认是gunicorn
proc_name = 'gunicorn_room'

不使用配置文件

gunicorn drf_admin.wsgi –preload -b 0.0.0.0:8080

 还是报一样的错

gunicorn版本

gunicorn==20.1.0
Django==2.2.20

有没有大神知道什么原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值