gpt4 book ai didi

docker - 运行 docker 容器时出错 : starting container process caused "exec:\"python\": executable file not found in $PATH": unknown

转载 作者:行者123 更新时间:2023-12-02 22:03:51 24 4
gpt4 key购买 nike

我正在尝试对一个简单的 Python-Flask 应用程序进行 dockerize,但在运行容器时遇到错误。

docker:来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:344:启动容器进程导致“exec:\”python\”:在 $PATH 中找不到可执行文件”:未知。

本地主机上的工作目录:

/home/ubuntu/flask_web
- app.py
- Dockerfile
- requirements.txt

应用程序.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 Web 应在端口 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.

最佳答案

上面代码构建的 docker 镜像中没有 /usr/bin/python 。但是有/usr/bin/python3。因此,您可以直接使用 python3 作为您的 ENTRYPOINT 或创建符号链接(symbolic link)。

关于docker - 运行 docker 容器时出错 : starting container process caused "exec:\"python\": executable file not found in $PATH": unknown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55343991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com