简体   繁体   English

IBM Cloud Functions:如何运行Docker函数?

[英]IBM Cloud Functions: How to run a Docker function?

FROM python:3.7
COPY ./src /data/python
WORKDIR /data/python
RUN pip install --no-cache-dir flask
EXPOSE 8080
CMD ["python", "main.py"]
  • main.py main.py
import os
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return {'body': os.environ.items()}


def run():
    app.run(host='0.0.0.0', port=8080)


if __name__ == '__main__':
    run()

click invoke result点击调用结果

[
  "2021-01-29T09:53:30.727847Z    stdout: * Serving Flask app \"main\" (lazy loading)",
  "2021-01-29T09:53:30.727905Z    stdout: * Environment: production",
  "2021-01-29T09:53:30.727913Z    stdout: WARNING: This is a development server. Do not use it in a production deployment.",
  "2021-01-29T09:53:30.727918Z    stdout: Use a production WSGI server instead.",
  "2021-01-29T09:53:30.727923Z    stdout: * Debug mode: off",
  "2021-01-29T09:53:30.731130Z    stderr: * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)",
  "2021-01-29T09:53:30.747035Z    stderr: 172.30.139.167 - - [29/Jan/2021 09:53:30] \"\u001b[33mPOST /init HTTP/1.1\u001b[0m\" 404 -",
  "2021-01-29T09:53:30.748Z       stderr: The action did not initialize or run as expected. Log data might be missing."
]

I've added the Docker container to IBM Cloud Functions我已将Docker容器添加到IBM Cloud Functions中

What would be the best way to approach this?解决这个问题的最佳方法是什么?

FROM python:3.7
COPY ./src /data/python
WORKDIR /data/python
RUN pip install --no-cache-dir flask
EXPOSE 8080
CMD ["python", "main.py"]
  • main.py main.py
import os
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return {'body': os.environ.items()}


def run():
    app.run(host='0.0.0.0', port=8080)


if __name__ == '__main__':
    run()

click invoke result点击调用结果

[
  "2021-01-29T09:53:30.727847Z    stdout: * Serving Flask app \"main\" (lazy loading)",
  "2021-01-29T09:53:30.727905Z    stdout: * Environment: production",
  "2021-01-29T09:53:30.727913Z    stdout: WARNING: This is a development server. Do not use it in a production deployment.",
  "2021-01-29T09:53:30.727918Z    stdout: Use a production WSGI server instead.",
  "2021-01-29T09:53:30.727923Z    stdout: * Debug mode: off",
  "2021-01-29T09:53:30.731130Z    stderr: * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)",
  "2021-01-29T09:53:30.747035Z    stderr: 172.30.139.167 - - [29/Jan/2021 09:53:30] \"\u001b[33mPOST /init HTTP/1.1\u001b[0m\" 404 -",
  "2021-01-29T09:53:30.748Z       stderr: The action did not initialize or run as expected. Log data might be missing."
]

I've added the Docker container to IBM Cloud Functions我已将Docker容器添加到IBM Cloud Functions中

What would be the best way to approach this?解决这个问题的最佳方法是什么?

FROM python:3.7
COPY ./src /data/python
WORKDIR /data/python
RUN pip install --no-cache-dir flask
EXPOSE 8080
CMD ["python", "main.py"]
  • main.py main.py
import os
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return {'body': os.environ.items()}


def run():
    app.run(host='0.0.0.0', port=8080)


if __name__ == '__main__':
    run()

click invoke result点击调用结果

[
  "2021-01-29T09:53:30.727847Z    stdout: * Serving Flask app \"main\" (lazy loading)",
  "2021-01-29T09:53:30.727905Z    stdout: * Environment: production",
  "2021-01-29T09:53:30.727913Z    stdout: WARNING: This is a development server. Do not use it in a production deployment.",
  "2021-01-29T09:53:30.727918Z    stdout: Use a production WSGI server instead.",
  "2021-01-29T09:53:30.727923Z    stdout: * Debug mode: off",
  "2021-01-29T09:53:30.731130Z    stderr: * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)",
  "2021-01-29T09:53:30.747035Z    stderr: 172.30.139.167 - - [29/Jan/2021 09:53:30] \"\u001b[33mPOST /init HTTP/1.1\u001b[0m\" 404 -",
  "2021-01-29T09:53:30.748Z       stderr: The action did not initialize or run as expected. Log data might be missing."
]

I've added the Docker container to IBM Cloud Functions我已将Docker容器添加到IBM Cloud Functions中

What would be the best way to approach this?解决这个问题的最佳方法是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 IBM Cloud Functions 中运行 Puppeteer - Run Puppeteer in IBM Cloud Functions 尝试在IBM Cloud Functions中运行代码 - Trying to run code in IBM Cloud Functions 在IBM Cloud Functions中将函数输出作为电子邮件发送 - Send function output as an email in IBM cloud functions 无法通过 docker java 运行时从 ibm 云函数操作获取结果 json - not able to get result json from ibm cloud function action through docker java run time 如何将IBM Cloud Functions上的操作与数据库连接? - How to connect an action on IBM Cloud Functions with a database? 如何检查IBM Cloud Functions中的POST正文? - How to inspect the POST body in IBM Cloud Functions? 如何验证 IBM Cloud Function 以使用 IBM Cloud Foundry API - how to authenticate IBM Cloud Function to use IBM Cloud Foundry API 如何在IBM Bluemix Expertises上运行Docker部署 - How to run Docker Deployments at IBM Bluemix Expertises 是否可以将视频文件上传到IBM Cloud Functions / OpenWhisk函数并对其进行编码? - Is it possible to upload a video file to IBM Cloud Functions / OpenWhisk function and encode it? IBM Cloud Functions:是否可以具有由多个Javascript文件组成的函数? - IBM Cloud Functions: Is it possible to have a function made of multiple Javascript files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM