Streamlit with Poetry 运行 在本地 Docker 但不在云端 运行

Streamlit with Poetry running in Docker locally but not on Cloud Run

我遇到过我能够 运行 我的本地设备上的 Docker 文件没有任何问题,但是在云端 运行 它失败并在日志中显示以下错误:

Docker文件如下所示:

FROM debian:stable-slim

WORKDIR /root
RUN apt-get update && apt-get upgrade -y && apt-get install -y curl python3 python3-dev python3-venv build-essential \
  libgmp3-dev && curl -sSL https://install.python-poetry.org | python3 -
ADD poetry.lock .
ADD pyproject.toml .
ADD main.py .
ENV PATH "/root/.local/bin:$PATH"
RUN poetry install -vvv
ENV STREAMLIT_SERVER_PORT 8080
RUN poetry run echo $PATH
RUN poetry run which python
RUN poetry run which streamlit
CMD ["poetry", "run", "streamlit", "run", "main.py"]

我期待 Docker 确保在本地和云端具有相同的执行环境 运行。

此外,echo $PATH / which python / which streamlit 命令 return 在本地和 Cloud Build 上执行类似的操作。

本地我得到:

Step 10/13 : RUN poetry run echo $PATH
 ---> Running in 1e00651356b2
/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 1e00651356b2
 ---> bd9b9acd4152
Step 11/13 : RUN poetry run which python
 ---> Running in 58b5348154a1
/root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/python
Removing intermediate container 58b5348154a1
 ---> d3a8588626f0
Step 12/13 : RUN poetry run which streamlit
 ---> Running in 72ea21408e0c
/root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/streamlit
Removing intermediate container 72ea21408e0c
 ---> 3f7fa5ded8ec
Step 13/13 : CMD ["poetry", "run", "streamlit", "run", "main.py"]
 ---> Running in ea06f67b0930
Removing intermediate container ea06f67b0930
 ---> ae2349318933
Successfully built ae2349318933
Successfully tagged esoapp:latest

In Cloud Build I see:
Step #0: INFO[0026] RUN poetry run echo $PATH                    
Step #0: INFO[0026] Taking snapshot of full filesystem...        
Step #0: INFO[0034] cmd: /bin/sh                                 
Step #0: INFO[0034] args: [-c poetry run echo $PATH]             
Step #0: INFO[0034] Running: [/bin/sh -c poetry run echo $PATH]  
Step #0: /root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Step #0: INFO[0035] Taking snapshot of full filesystem...        
Step #0: INFO[0036] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0036] RUN poetry run which python                  
Step #0: INFO[0036] cmd: /bin/sh                                 
Step #0: INFO[0036] args: [-c poetry run which python]           
Step #0: INFO[0036] Running: [/bin/sh -c poetry run which python] 
Step #0: INFO[0036] Pushing layer gcr.io/personal-313102/eso-app/cache:88561d733a1fd5ca03e6481ff992723526198d61ba0abe93ab912eaa155da06a to cache now 
Step #0: INFO[0036] Pushing image to gcr.io/personal-313102/eso-app/cache:88561d733a1fd5ca03e6481ff992723526198d61ba0abe93ab912eaa155da06a 
Step #0: /root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/python
Step #0: INFO[0037] Taking snapshot of full filesystem...        
Step #0: INFO[0038] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0038] RUN poetry run which streamlit               
Step #0: INFO[0038] cmd: /bin/sh                                 
Step #0: INFO[0038] args: [-c poetry run which streamlit]        
Step #0: INFO[0038] Running: [/bin/sh -c poetry run which streamlit] 
Step #0: INFO[0038] Pushing layer gcr.io/personal-313102/eso-app/cache:498bfad933dca72234af0985b0ed384effed32958351e5727a4cbc56a2670d13 to cache now 
Step #0: INFO[0038] Pushing image to gcr.io/personal-313102/eso-app/cache:498bfad933dca72234af0985b0ed384effed32958351e5727a4cbc56a2670d13 
Step #0: INFO[0038] Pushed gcr.io/personal-313102/eso-app/cache@sha256:32f47b0699c392a7be4e8243545975348475956e35fd51347348168a07a714db 
Step #0: /root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/streamlit
Step #0: INFO[0038] Taking snapshot of full filesystem...        
Step #0: INFO[0040] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0040] CMD ["poetry", "run", "streamlit", "run", "main.py"] 
Step #0: INFO[0040] No files changed in this command, skipping snapshotting. 
Step #0: INFO[0040] Pushing layer gcr.io/personal-313102/eso-app/cache:7a16d1344c60a8740190534cfa44fed333547d60231720fcea3820ebd42ecf87 to cache now 
Step #0: INFO[0040] Pushing image to gcr.io/personal-313102/eso-app/cache:7a16d1344c60a8740190534cfa44fed333547d60231720fcea3820ebd42ecf87 
Step #0: INFO[0040] Pushed gcr.io/personal-313102/eso-app/cache@sha256:c4e57c77bd9dccfbbe3aca001bdf3fc26bccca20ed2879fc143a91ccdbee895a 
Step #0: INFO[0041] Pushed gcr.io/personal-313102/eso-app/cache@sha256:4198599d679af55fda0cf5cc8407bac0eb0ddb110e1e503a06663df9947523a6 
Step #0: INFO[0041] Pushing image to gcr.io/personal-313102/eso-app:0a1bd22ce692a52f231221778abea5561ac736e7 
Step #0: INFO[0043] Pushed gcr.io/personal-313102/eso-app@sha256:72473a2099329f7a4fb2a5933c7d3c749906840b27967752d06c24ca3f71acc5 
Finished Step #0
Starting Step #1

关于为什么在 Cloud 中找不到 streamlit 二进制文件的任何想法 运行?

我自己深入研究,发现主目录在 Cloud 运行 中很混乱。

这显然是一个已知问题 -> https://cloud.google.com/run/docs/issues#home

通过将 Dockerfile 中的 CMD 命令更改为来解决 CMD HOME=/root poetry run streamlit run main.py