簡體   English   中英

賽普拉斯:容器無法啟動。 無法啟動並監聽 PORT 定義的端口

[英]Cypress: Container failed to start. Failed to start and then listen on the port defined by the PORT

我正在嘗試使用雲構建部署我的柏樹測試,但是,我在雲構建中不斷收到以下錯誤。

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

我不確定我做錯了什么。

這是我的 docker 文件

FROM cypress/browsers:node13.8.0-chrome81-ff75

WORKDIR /root

COPY package*.json ./
RUN npm install

COPY . .

CMD ["npm", "run", "cy:run:chrome"]

這是我的cloudbuild.yaml

steps:
    # Build image  
    - name: 'gcr.io/cloud-builders/docker'
      args: [ 'build', '-t', 'gcr.io/app-trick/cypress-tests', './']
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/app-trick/cypress-tests']          

    - name: 'gcr.io/cloud-builders/gcloud'
      args:
      - 'run'
      - 'deploy'
      - 'cypress-tests'
      - '--image'
      - 'gcr.io/app-trick/cypress-tests'
      - '--region'
      - 'us-east4'
      - '--platform'
      - 'managed'
      - '--allow-unauthenticated'

這是我的 package.json

{
  "name": "cypress_nid",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "cy:open": "npx cypress open --port $PORT",
    "cy:run": "npx cypress run --port $PORT",
    "cy:run:chrome": "npx cypress run --browser chrome --port $PORT",
    "cy:run:firefox": "npx cypress run --browser firefox --port $PORT",
    "cy:run:record": "npx cypress run --record --port $PORT"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^4.11.0",
    "cypress-promise": "^1.1.0"
  },
  "dependencies": {
    "D": "^1.0.0",
    "express": "^4.17.1"
  }
}

您的Dockerfile中不需要EXPOSE 8080

相反,您需要通過監聽$PORT上的請求來遵守 容器運行時契約 這通常是8080 ,但你不應該假設它。

這意味着您需要將--port參數傳遞給cypress run ,並使用$PORT環境變量,因此您的腳本將具有以下內容:

"cy:run:chrome": "npx cypress run --browser chrome --port $PORT",

暫無
暫無

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

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