You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Docker中运行uWSGI提示“无此文件或目录”问题求助

解决Docker启动uWSGI时的"没有该文件或目录"错误

这个错误我踩过好几次——Docker在解析你的启动命令时完全跑偏了:它把整个uwsgi --http :80 ...的字符串当成了单个可执行文件的路径,而不是把uwsgi作为命令,后面的内容作为参数。系统自然找不到一个叫uwsgi --http :80 ...的文件,所以报错了。

给你两种场景的解决方案:

场景1:用docker run直接启动容器

如果你是在终端里直接敲docker run命令启动的,大概率是把整个uWSGI命令用引号包起来了,比如:

docker run your-image "uwsgi --http :80 -s /tmp/uwsgi.sock --pidfile /var/run/uwsgi.pid --wsgi-file /app/api.py -M -p 4 --die-on-term --callable app -d /tmp/uwsgi.log"

改成下面两种方式之一就行:

  • 方式一:拆分命令与参数(推荐)
    去掉整体的引号,让Docker分别识别命令和每个参数:
    docker run your-image uwsgi --http :80 -s /tmp/uwsgi.sock --pidfile /var/run/uwsgi.pid --wsgi-file /app/api.py -M -p 4 --die-on-term --callable app -d /tmp/uwsgi.log
    
  • 方式二:用shell执行命令
    如果参数太复杂,也可以用sh -c把整个命令交给shell解析:
    docker run your-image sh -c "uwsgi --http :80 -s /tmp/uwsgi.sock --pidfile /var/run/uwsgi.pid --wsgi-file /app/api.py -M -p 4 --die-on-term --callable app -d /tmp/uwsgi.log"
    

场景2:在Dockerfile里配置启动命令

如果是Dockerfile里的CMD或ENTRYPOINT写错了,比如你用了单字符串的数组形式:

CMD ["uwsgi --http :80 -s /tmp/uwsgi.sock --pidfile /var/run/uwsgi.pid --wsgi-file /app/api.py -M -p 4 --die-on-term --callable app -d /tmp/uwsgi.log"]

这时候Docker同样会把这个字符串当成单个可执行文件。改成下面两种正确写法:

  • 方式一:数组形式拆分参数(推荐用于生产环境)
    把命令和每个参数拆成数组的元素:
    CMD ["uwsgi", "--http", ":80", "-s", "/tmp/uwsgi.sock", "--pidfile", "/var/run/uwsgi.pid", "--wsgi-file", "/app/api.py", "-M", "-p", "4", "--die-on-term", "--callable", "app", "-d", "/tmp/uwsgi.log"]
    
  • 方式二:shell形式的CMD
    直接写命令字符串,Docker会自动用sh -c执行:
    CMD uwsgi --http :80 -s /tmp/uwsgi.sock --pidfile /var/run/uwsgi.pid --wsgi-file /app/api.py -M -p 4 --die-on-term --callable app -d /tmp/uwsgi.log
    

额外检查

别忘了确认你的Docker镜像里已经安装了uWSGI!如果是Python项目,在Dockerfile里加一行安装命令:

RUN pip install uwsgi

内容的提问来源于stack exchange,提问作者PlayMa256

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:13:28