【问题标题】:gunicorn: command not found djangogunicorn:找不到命令 django
【发布时间】:2018-12-09 20:13:39
【问题描述】:

使用Docker安装gunicorn,无法使用gunicorn命令。

要启动 Django,我的 docker-compose.yaml 中有这一行:

command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn myproject.wsgi -b 0.0.0.0:8000"

这会导致 bash: gunicorn: command not found

当我构建 Docker 映像时,它说 gunicorn 已成功安装。

我的 Dockerfile 看起来像:

FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /config
ADD requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src;
WORKDIR /src

我一直使用这个http://ruddra.com/2016/08/14/docker-django-nginx-postgres/ 作为指导。

【问题讨论】:

  • 您是否也使用pip -r 安装要求?
  • 嗯,看来你是在Dockerfile做的
  • 是的,运行 pip install -r /config/requirements.txt
  • 为确保,使用docker exec -it dg01 bash 转到您的容器(此处为dg01),然后在其容器的命令行上执行pip show gunicorn,如果没有返回任何东西gunicorn 未安装在您的容器和其他......!
  • 没有返回任何东西!你知道我从这里去哪里吗? @BenyaminJafari

标签: django docker nginx gunicorn


【解决方案1】:

如果您发现 gunicorn 不存在,可能是因为 docker 镜像可能使用 requirements.txt 的缓存层,其中没有 gunicorn 作为依赖项。 因此,这将导致不安装 gunicorn,同时在单独的 RUN 命令中指定 pip install gunicorn 将起作用。

解决方案:

在对 requirements.txt 进行编辑时构建 docker 映像而不进行缓存

docker build --no-cache .

【讨论】:

    猜你喜欢
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2022-06-10
    • 2012-01-05
    • 2012-08-01
    • 2022-10-19
    相关资源
    最近更新 更多