英文:
Uploading a docker image to gcloud leads to service unavailable
问题
这是我的Docker文件代码:
FROM python:3.9-slim
RUN apt-get update && apt-get install -y build-essential
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir flask gunicorn flask_session firebase_admin python-dotenv
EXPOSE 8080
ENV PORT=8080
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 wbvaa:app
我已经尝试在本地构建镜像并使用以下命令进行测试:
docker build -t test-image:latest .
当运行:docker run -d -p 8080:8080 test-image:latest
这在本地工作正常,我可以在localhost:8080上看到我的应用程序正在运行。
但是,当尝试将相同的镜像部署到Google Cloud(gcloud)时,出现"服务不可用"错误。部署所使用的命令如下:
gcloud builds submit --tag gcr.io/wbvaa-web/flask-fire
gcloud beta run deploy --image gcr.io/wbvaa-web/flask-fire
出现了什么问题?
英文:
here is my docker file code:
FROM python:3.9-slim
RUN apt-get update && apt-get install -y build-essential
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir flask gunicorn flask_session firebase_admin python-dotenv
EXPOSE 8080
ENV PORT=8080
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 wbvaa:app
I have tried locally building the image and testing it using these commands:
docker build -t test-image:latest .
when run by: docker run -d -p 8080:8080 test-image:latest
this works fine, and I can see my application running on localhost:8080
but when trying to deploy this same image into gcloud it results 'service unavailable' error. The commands used for deployment:
gcloud builds submit --tag gcr.io/wbvaa-web/flask-fire
gcloud beta run deploy --image gcr.io/wbvaa-web/flask-fire
what is going wrong?
答案1
得分: 1
我已解决了这个问题。对于 Gcloud 日志,我发现问题是 Cloud Run 无法解析文件路径(Firebase 配置 JSON 文件的路径)。文件路径是使用 os 库提供的绝对路径,并且 Docker 可以解析它。但 Cloud Run 似乎找不到该文件。
改为将配置作为对象传递,问题得到解决!
> 编辑:
Gcloud 会自动忽略在 gitignore 文件中列出的文件。
英文:
I have resolved the issue. For Gcloud logs I found that the error was cloud run could not resolve a file path (of the firebase config json). File path was given as absolute path using os library and docker could resolve it. Somehow cloud run could not find the file.
Passed the config as object instead and it worked!
> Edit:
Gcloud automatically ignores files in gitignore file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论