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

Azure部署Docker容器报错/bin/sh: 1: [gunicorn,: not found如何解决

问题原因与解决方案

核心错误原因

你遇到的/bin/sh: 1: [gunicorn,: not found报错本质是CMD指令的JSON格式被非法转义破坏,导致Docker无法正确解析启动命令:

  • 你的CMD指令中使用了Windows风格的路径分隔符\(dash_app\dashboard:server),而Linux环境下\是转义字符,会直接破坏整个JSON数组的结构
  • 格式错误的CMD会被Docker降级为shell模式执行,此时整个["gunicorn", "--bind"...]字符串会被当成单个命令传入shell,shell会把开头的[gunicorn,识别为命令名,因此抛出找不到命令的错误

次要潜在问题

你先以root身份安装依赖,再切换到非root用户运行,少数场景下会出现非root用户的PATH环境变量未包含gunicorn安装路径的问题,也会导致命令找不到。

修复步骤

1. 修正启动命令

将CMD中的路径分隔符替换为Linux风格的正斜杠/,确保JSON格式合法:

# 修正前
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "dash_app\dashboard:server"]
# 修正后
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "dash_app/dashboard:server"]

如果修改后仍然报错,可以直接用Python模块方式调用gunicorn,规避PATH查找问题:

CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "dash_app/dashboard:server"]

2. 优化Dockerfile顺序(可选,避免潜在权限问题)

调整指令顺序,统一在工作目录下操作,避免路径混乱:

FROM python:3.8-slim-buster

EXPOSE 5000

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# 提前切换工作目录,所有后续操作都在/app下执行
WORKDIR /app

COPY requirements.txt .
RUN python -m pip install --no-cache-dir -r requirements.txt

COPY . /app

RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "dash_app/dashboard:server"]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 22:27:02