[英]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.