枪:找不到烧瓶
我已经创建了一个烧瓶应用程序,并且使用此命令在本地运行良好 gunicorn-工作者2 -B:5000 WSGI:APP
现在,我正在尝试在Docker中运行相同的应用程序,并且正在获得./ Gunicorn_starter.sh:第3行:Gunicorn:找不到命令
。
我的dockerfile:
FROM python:3.5
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt --user
COPY . .
RUN chmod +x gunicorn_starter.sh
CMD ["./gunicorn_starter.sh" ]
gunicorn_starter.sh:
#!/bin/sh
source venv/bin/activate
gunicorn --workers 2 -b :5000 wsgi:app
wsgi.py:
from app import app
if __name__ == "__main__":
app.run(debug=True)
文件结构:
flask_app
>venv
dockerfile
gunicorn_starter.sh
app.py
wsgi.py
requirements.txt
我确实有gunicorn in sequemnemnets.txt文件。
我尝试了以下链接:
gunicorn在运行带有Venv
安装枪nocorn /a>
gunicorn throw rorral-无法在$ path上找到可执行文件/nginx)
我不知道为什么它不起作用,请帮助您。
I have created a flask app and it is running fine locally using this commandgunicorn --workers 2 -b :5000 wsgi:app
Now I'm trying to run the same application in docker and I'm getting ./gunicorn_starter.sh: line 3: gunicorn: command not found
.
my dockerfile:
FROM python:3.5
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt --user
COPY . .
RUN chmod +x gunicorn_starter.sh
CMD ["./gunicorn_starter.sh" ]
gunicorn_starter.sh:
#!/bin/sh
source venv/bin/activate
gunicorn --workers 2 -b :5000 wsgi:app
wsgi.py:
from app import app
if __name__ == "__main__":
app.run(debug=True)
File structure:
flask_app
>venv
dockerfile
gunicorn_starter.sh
app.py
wsgi.py
requirements.txt
I do have gunicorn in requiremnets.txt file.
I have tried following links:
gunicorn not found when running a docker container with venv
Installed gunicorn but it is not in venv/bin folder
Gunicorn throwing error - cannot find executable on $PATH (Docker/Nginx)
I couldn't figure out why it is not working, please help Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所显示的最重要的问题可能是您正在尝试
复制
venv
目录中的主机的虚拟环境中的docker映像,但虚拟环境不是跨装置的便携式。因此,如果非标准源
命令成功(如果/bin/sh
实际上是GNU bash),则可以尝试运行./ venv/bin/gunicorn
,但这连接到容器内不存在的Python安装。您应该做的第一件事是编写a
.dockerignore
文件其中包括将使您的基于主机的虚拟环境置于图像构建之外的行。这避免了Python不匹配的问题(也许甚至是相同的OS),并且还将使
Docker build
序列运行速度明显更快。由于在Docker中,Docker映像是从其他Python安装中隔离的,因此您在这里不需要虚拟环境。一种标准方法是将软件包安装到“系统” python中,但在隔离的图像中。这意味着您不需要“激活”任何东西,也可以与Shell-Script包装器分配。
简化的Dockerfile看起来像:
Probably the most significant issue in what you show is that you're trying to
COPY
your host's virtual environment in thevenv
directory into the Docker image, but virtual environments aren't portable across installations. So if the non-standardsource
command succeeds (if/bin/sh
is actually GNU bash) you could be trying to run./venv/bin/gunicorn
, but that's connected to a Python installation that doesn't exist inside the container.The first thing you should do is write a
.dockerignore
file that includes the lineThat will keep your host-based virtual environment out of the image build. This avoids problems where the Python doesn't match (maybe it's not even the same OS) and also will make the
docker build
sequence run significantly faster.The Docker image is isolated from other Python installations by virtue of being in Docker, so you don't need a virtual environment here. One standard approach is to install packages into the "system" Python, but inside the isolated image. This means you don't need to "activate" anything and you can dispense with the shell-script wrapper as well.
A simplified Dockerfile could look like: