我正在尝试对一个简单的Python-Flask应用程序进行docker化,但是在运行容器时出现错误。
docker:来自守护程序的错误响应:OCI运行时创建失败:container_linux.go:344:启动容器进程导致“ exec:\” python \”:在$ PATH中找不到可执行文件”:未知。
本地主机上的Workdir:
/home/ubuntu/flask_web
- app.py
- Dockerfile
- requirements.txt
app.py
#flask_web/app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hey, we have Flask in a Docker container'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Dockerfile
FROM ubuntu:16.04
MAINTAINER xyz "xyz@gmail.com"
RUN apt-get update \
&& apt-get install -y software-properties-common vim \
&& add-apt-repository ppa:jonathonf/python-3.6 \
&& apt-get update -y \
&& apt-get install -y build-essential python3.6 python3.6-dev python3-pip python3.6-venv \
&& pip3 install --upgrade pip
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
命令:
docker build -t flask-test:latest .
docker run -p 5000:5000 flask-test
预期:Flask网站应在端口5000上运行
实际结果:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown.
答案 0 :(得分:2)
由以上代码构建的docker映像中没有/usr/bin/python
。但是有/usr/bin/python3
。因此,您既可以直接将python3
用作ENTRYPOINT
,也可以创建符号链接。
答案 1 :(得分:0)
我遇到了同样的问题,只是它大喊了 344 以外的其他数字
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown.
和 docker 文件是
FROM ubuntu:20.04
RUN apt-get update -y
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip3 install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
我换了线
ENTRYPOINT [ "python" ]
到ENTRYPOINT [ "python3" ]
现在它工作正常。
这样做的原因是上面我使用的是 Python3,所以没有 Python 的候选者,而是 Python3 的候选者。
RUN apt-get install -y python3
RUN apt-get install -y python3-pip