运行 docker 容器时出错:启动容器进程导致“exec:"python“:$PATH 中找不到可执行文件":未知 [英] Error running docker container: starting container process caused "exec: "python": executable file not found in $PATH": unknown

查看:48
本文介绍了运行 docker 容器时出错:启动容器进程导致“exec:"python“:$PATH 中找不到可执行文件":未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 dockerize 一个简单的 Python-Flask 应用程序,但在运行容器时出现错误.

I am trying to dockerize a simple Python-Flask application but I am getting an error while running my container.

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

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.

本地主机上的工作目录:

Workdir on localhost:

/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 web 应该在端口 5000 上运行

Expected : Flask web should run on port 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 或者创建一个符号链接.

There is no /usr/bin/python in a docker image built by the code above. But there is /usr/bin/python3. So you could either use python3 directly as your ENTRYPOINT or create a symlink.

这篇关于运行 docker 容器时出错:启动容器进程导致“exec:"python“:$PATH 中找不到可执行文件":未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆