我在flask中使用了这个dockerfile:
FROM python:3.8-slim-buster
WORKDIR /python-docker
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
它工作正常,在我的目录中,我有requirements.txt和一个非常简单的app.py文件:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_geek():
return '<h1>Hello from Flask & Docker</h2>'
if __name__ == "__main__":
app.run(debug=True)
我想把它作为一个无发行版镜像使用,所以我在这个dockerfile上构建:
FROM python:3.8-slim-buster as build-env
ADD / /app
WORKDIR /app
RUN pip3 install --upgrade pip
RUN pip install -r ./requirements.txt
FROM gcr.io/distroless/python3-debian10
COPY --from=build-env /app /app
COPY --from=build-env /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
WORKDIR /app
ENV PYTHONPATH=/usr/local/lib/python3.8/site-packages
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
编译时没有错误,但当我运行时:sudo docker run python-dockerdistro
我得到这个错误:/usr/bin/python3.7:无法打开文件'python3':[错误2]没有该文件或目录
你知道如何解决这个错误吗?先谢谢你了
1条答案
按热度按时间uyhoqukh1#
gcr.io/distroless/python3-debian10
图像的ENTRYPOINT是Python 3:但是,您的
CMD
是[ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
你实际上是在尝试运行Python两次:
只需将
CMD
更改为仅["-m" , "flask", "run", "--host=0.0.0.0"]