簡體   English   中英

Cloud Run 錯誤:容器無法啟動。 無法啟動然后偵聽 PORT 環境變量定義的端口。 - Django

[英]Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. - Django

我剛開始問關於 SO 的問題,所以請耐心等待。 我知道已經有很多關於這個的答案,但沒有一個有效。 我一直致力於制作 Django web 應用程序,現在我必須部署它,以便您可以在移動設備上訪問它。 我一直試圖讓它在 Google Cloud Run 上運行,但沒有成功。 我制作了 Docker 容器,它在本地運行良好,但是當我嘗試部署該容器時,出現以下錯誤: Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information. Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.

日志循環回到同一頁面,沒有其他信息。 我嘗試將 docker-compose.yml 和 Dockerfile 中的端口切換為 80、8000、8080 以及兩者之間的任何變化,但沒有成功。 我知道 Django 你打算使用 App Engine,但我已經在 sqlite3 數據庫中加載了太多東西,我能找到的關於 App 引擎的所有資源都是關於 PostGres 的,我沒有時間轉換到。 我還確保在settings.py中包含ALLOWED_HOST 0.0.0.0 ,所以我不知道發生了什么。 以下是我的 Dockerfile 的內容:

ENV PYTHONUNBUFFERED 1
EXPOSE 8080
ENV PORT 8080
ENV HOST 0.0.0.0
RUN mkdir /Exeplore
WORKDIR /Exeplore
COPY requirements.txt /Exeplore/
RUN pip install -r requirements.txt
COPY . /Exeplore/

這是我的docker-compose.yml文件的內容:

  web:
    build: .
    environment:
      MYENV: EXAMPLE
    volumes:
      - .:/code
  web_migrate:
    extends:
      service: web
    command: python manage.py migrate
  web_run:
    extends:
      service: web
    command: python manage.py runserver 0.0.0.0:8080
    ports:
      - "8080:8080"

這是我從 google cloud run 得到的錯誤,日志只鏈接到同一頁面:

這是我從 google cloud run 得到的錯誤,日志只是鏈接到同一頁面

我希望我做對了,但如果需要其他任何東西,請告訴我。

將 Docker 組合命令添加到 Dockerfile

ENV PYTHONUNBUFFERED 1
EXPOSE 8080
ENV PORT 8080
ENV HOST 0.0.0.0
RUN mkdir /Exeplore
WORKDIR /Exeplore
COPY requirements.txt /Exeplore/
RUN pip install -r requirements.txt
COPY . /Explore/
ENTRYPOINT [ "python" "manage.py"]
CMD [ "runserver", "0.0.0.0:8080" ]

您現在應該能夠使用必要的參數調用 python 應用程序,例如執行默認命令。

docker run -p 8080:8080 my_container

在上面的Dockerfile中:

  • 入口點將調用python解釋器並調用manage.py應用程序。
  • CMD(命令)將調用撰寫文件中使用的附加參數(即runserver 0.0.0.0:8080 )。 您可以通過添加必要的參數(即migrate )來覆蓋默認行為。

例如

docker run -p 8080:8080 my_container migrate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM