尝试在App Engine上运行Docker Flask应用时出现错误502

时间:2019-06-22 17:23:00

标签: python docker google-app-engine flask

我想在包含基本Flask应用程序的App Engine上部署Docker映像。另外,此应用程序将成为我前端的网络套接字端点。

部署成功。 但是我收到错误502。

我已经阅读了文档,尝试了许多配置,但是我不理解它的工作原理,如果有人有什么想法,我将不胜感激。

error

enter image description here

我的项目结构:

- socket/
  - socket/
    - main.py
    - Dockerfile
    - app.yaml
    - requirements.txt
  - cloudbuild.yaml

main.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    return 'Hello World!'


if __name__ == '__main__':
    # This will be only used locally. App Engine will use gunicorn.
    app.run(host='127.0.0.1', port=8080, debug=True)

requirements.txt

Flask==1.0.3
Flask-Sockets==0.2.1
gunicorn==19.9.0

Dockerfile

FROM python:2.7

WORKDIR /app

COPY . /app

EXPOSE 8080

RUN pip install --trusted-host pypi.python.org -r requirements.txt

ENTRYPOINT ["gunicorn","--bind=0.0.0.0:8080", "-k flask_sockets.worker", "main:app"]

app.yaml

runtime: custom
env: flex
service: socket
entrypoint: gunicorn -b :$PORT -k flask_sockets.worker main:app
manual_scaling:
  instances: 1
network:
  session_affinity: true

cloudbuild.yaml

steps:
  # Decrypt env secrets
  - name: gcr.io/cloud-builders/gcloud
    args:
      - kms
      - decrypt
      - --ciphertext-file=./socket/conf/gcp_credentials.json.enc
      - --plaintext-file=./socket/conf/gcp_credentials.json
      - --location=global
      - --keyring=cloudbuild-env
      - --key=cloudbuild-env
    id: decrypt
  # Build the docker image
  - name: gcr.io/cloud-builders/docker
    args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/tweets-socket-dataflow', './socket/' ]
    id: build
  # Deploy the image
  - name: gcr.io/cloud-builders/gcloud
    args: ['app', 'deploy', './socket/app.yaml', '-v', '1-socket-latest']
    id: deploy
timeout: 600s

这实际上在本地有效

使用了Docker命令

docker run -it -d -p 8080:8080 144005a4e426

docker ps

c2763d0b8b75        144005a4e426        "gunicorn --bind=0.0…"   3 seconds ago       Up 1 second         0.0.0.0:8080->8080/tcp   sleepy_ganguly

http:127.0.0.1:8080

enter image description here

0 个答案:

没有答案