简体   繁体   English

如何在IBM Cloud功能中运行docker映像?

[英]How to run a docker image in IBM Cloud functions?

I have a simple Python program that I want to run in IBM Cloud functions. 我有一个想要在IBM Cloud函数中运行的简单Python程序。 Alas it needs two libraries (O365 and PySnow) so I have to Dockerize it and it needs to be able to accept a Json feed from STDIN. las,它需要两个库(O365和PySnow),因此我必须对其进行Docker化,并且它必须能够接受来自STDIN的Json feed。 I succeeded in doing this: 我成功做到了:

FROM python:3
ADD requirements.txt ./
RUN pip install -r requirements.txt
ADD ./main ./main
WORKDIR /main
CMD ["python", "main.py"]

This runs with: cat env_var.json | docker run -i f9bf70b8fc89 它运行于: cat env_var.json | docker run -i f9bf70b8fc89 cat env_var.json | docker run -i f9bf70b8fc89

I've added the Docker container to IBM Cloud Functions like this: 我已经将Docker容器添加到IBM Cloud Functions中,如下所示:

ibmcloud fn action create e2t-bridge --docker [username]/e2t-bridge

However when I run it, it times out. 但是,当我运行它时,它会超时。

Now I did see a possible solution route, where I dockerize it as an Openwhisk application. 现在,我确实看到了一条可能的解决方案路线,在此将其泊坞为Openwhisk应用程序。 But for that I need to create a binary from my Python application and then load it into a rather complicated Openwhisk skeleton, I think? 但是为此,我需要从Python应用程序中创建一个二进制文件,然后将其加载到一个相当复杂的Openwhisk框架中,我认为呢?

But having a file you can simply run was is the whole point of my Docker, so to create a binary of an interpreted language and then adding it into a Openwhisk docker just feels awfully clunky. 但是拥有一个可以简单运行的文件是我Docker的全部重点,因此创建一种解释语言的二进制文件,然后将其添加到Openwhisk Docker中,感觉非常笨拙。

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

It turns out you don't need to create a binary, you just need to edit the OpenWhisk skeleton like so: 事实证明,您不需要创建二进制文件,只需要像下面这样编辑OpenWhisk框架即可:

# Dockerfile for example whisk docker action
FROM openwhisk/dockerskeleton

ENV FLASK_PROXY_PORT 8080

### Add source file(s)
ADD requirements.txt /action/requirements.txt
RUN cd /action; pip install -r requirements.txt

# Move the file to 
ADD ./main /action
# Rename our executable Python action
ADD /main/main.py /action/exec

CMD ["/bin/bash", "-c", "cd actionProxy && python -u actionproxy.py"]

And make sure that your Python code accepts a Json feed from stdin: 并确保您的Python代码接受来自stdin的Json feed:

json_input = json.loads(sys.argv[1])

The whole explaination is here: https://github.com/iainhouston/dockerPython 整个解释在这里: https : //github.com/iainhouston/dockerPython

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

相关问题 IBM云功能 - 如何使用和上传自己的库? - IBM Cloud Functions - How to use and upload own libraries? 将 docker 镜像部署到云运行时如何解决“容器启动失败错误” - How to resolve "container failed to start error" while deploying a docker image to cloud run 在 Google Cloud Run 中部署多阶段 Docker 映像 - Deploying multi-stage Docker image in Google Cloud Run Docker 映像在本地部署但在 Google Cloud Run 上失败 - Docker image deploys locally but fails on Google Cloud Run Google Cloud Run:将多个应用文件打包到一个 docker 映像中 - Google Cloud Run: Packaging multiple app files to one docker image 使用 IBM Cloud Functions 的 BOX SDK - Using BOX SDK from IBM Cloud Functions 如何在IBM Cloud Functions Action定制包中安装定制第三方库? - How can i install custom third party library in IBM Cloud functions action custom package? 如何使用自定义容器镜像部署谷歌云功能 - How to deploy google cloud functions using custom container image 如何在python3.6 docker镜像中安装ibm_db_dbi模块? - How to install ibm_db_dbi module in python3.6 docker image? 无法使用 docker run 命令运行 docker 镜像 - Unable to run docker image with docker run command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM