简体   繁体   English

使用 venv 运行 docker 容器时找不到 gunicorn

[英]gunicorn not found when running a docker container with venv

I'm trying to run a Docker container which complains with the error message: /bin/sh: gunicorn: not found .我正在尝试运行一个 Docker 容器,该容器抱怨错误消息: /bin/sh: gunicorn: not found Firing up the server locally without Docker works fine.在没有 Docker 的情况下本地启动服务器工作正常。 And building the image also works fine.并且构建图像也可以正常工作。 I'm new to docker so I don't know if anything looks weird in my Dockerfile..我是 docker 新手,所以我不知道我的 Dockerfile 中是否有任何奇怪的东西。

My Dockerfile:我的 Dockerfile:

FROM python:3.7-alpine

RUN adduser -D teamreacher
WORKDIR /home/teamreacher

# copy and install dependencies
COPY ./requirements.txt requirements.txt
RUN python -m venv venv
RUN venv/bin/pip install --upgrade pip
RUN venv/bin/pip install -r requirements.txt

# copy the app
COPY . .
RUN chmod +x boot.sh

RUN chown -R teamreacher:teamreacher ./
USER teamreacher

# expose port and run server
EXPOSE 5000

RUN source venv/bin/activate
CMD gunicorn -b :5000 --access-logfile - --error-logfile - wsgi:app

And my requirements.txt:还有我的 requirements.txt:

Flask==1.0.2
Flask-RESTful==0.3.6
Flask-SQLAlchemy==2.3.2
Flask-JWT==0.3.2
Flask-Cors==3.0.7
gunicorn==19.9.0

A RUN command creates a layer, it's like running the command in a new shell.一个RUN命令创建一个层,就像在一个新的 shell 中运行命令一样。 When it completes, the 'shell' exits.完成后,“外壳”退出。 So any following commands will not be affected.所以后面的任何命令都不会受到影响。

You can add a shell script (startup.sh) like,您可以添加一个 shell 脚本 (startup.sh),例如,

#!/bin/sh
source venv/bin/activate
gunicorn -b :5000 --access-logfile - --error-logfile - wsgi:app

then CMD ["./startup.sh"]然后CMD ["./startup.sh"]

PS: PS:

There is little interest for using virtual env in docker container.在 docker 容器中使用虚拟环境几乎没有兴趣。 A container is already an isolated environment and it's supposed to do only one thing.容器已经是一个孤立的环境,它应该只做一件事。

My packages installation looked like this:我的软件包安装如下所示:

RUN pip install -r requirements.txt --target=/app/python

I had to remove the --target=/app/python then pod status started showing Running (got fixed).我必须删除--target=/app/python然后 pod 状态开始显示正在Running (已修复)。

So the fix for me was:所以对我来说解决方法是:

RUN pip install -r requirements.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Docker 容器中运行 Flask 应用程序会导致“./boot.sh: 2: exec: gunicorn: not found” - Running a Flask app within a Docker container results in “./boot.sh: 2: exec: gunicorn: not found” Python 在 Docker 容器内运行 Gunicorn 时未解析主机(超时)(weasyprint 需要这样做) - Python not resolving host (timed out) when running with Gunicorn inside a Docker container (weasyprint needs to do that) Gunicorn自行运行,但不在docker容器中运行 - Gunicorn runs by itself but not in docker container 问:Python/Docker - 运行 docker 容器时,没有为 Django==4.0.2 找到匹配的发行版 - Q: Python/Docker - No matching distribution found for Django==4.0.2 when running docker container Django:在Docker容器中运行时找不到模块 - Django: module not found while running in Docker container 如何解决 Alpine docker 容器内 Flask 应用程序的 Gunicorn exec 上引发的“OSError:找不到 libc” - How to address 'OSError: libc not found' raised on Gunicorn exec of Flask app inside Alpine docker container Docker 容器中的 Gunicorn Flask 应用程序未暴露 - Gunicorn Flask application in Docker Container not getting Exposed 在 docker 容器上运行时,Flask 应用程序无法正常工作 - Flask App not working when running on docker container 运行Docker容器时没有此类文件或目录错误 - No such file or directory error when running Docker container 无法在 docker 容器中使用 gunicorn 连接到烧瓶应用程序 - Cannot connect to flask application with gunicorn in a docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM