[英]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.