如何在IBM Cloud功能中运行docker映像? [英] How to run a docker image in IBM Cloud functions?

查看:48
本文介绍了如何在IBM Cloud功能中运行docker映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要在IBM Cloud函数中运行的简单Python程序.las,它需要两个库(O365和PySnow),因此我必须对其进行Docker化,并且它必须能够接受来自STDIN的Json feed.我成功做到了:

  FROM python:3ADD requirements.txt ./RUN pip install -r requirements.txt添加./main ./mainWORKDIR/主要CMD ["python","main.py"] 

这与以下代码一起运行: cat env_var.json |泊坞窗运行-i f9bf70b8fc89

我已将Docker容器添加到IBM Cloud Functions中,如下所示:

ibmcloud fn操作创建e2t-bridge --docker [用户名]/e2t-bridge

但是,当我运行它时,它会超时.

现在,我确实看到了一条可能的解决方案路线,在其中将其作为Openwhisk应用程序进行了码头化.但是为此,我需要从Python应用程序中创建一个二进制文件,然后将其加载到一个相当复杂的Openwhisk框架中,我认为吗?

但是,拥有一个可以简单运行的文件是我Docker的全部工作,因此创建一种解释语言的二进制文件,然后将其添加到Openwhisk Docker中,感觉非常笨拙.

解决这个问题的最佳方法是什么?

解决方案

事实证明,您不需要创建二进制文件,只需要像这样编辑OpenWhisk框架即可:

 #例如Dockerfile拂docker操作从openwhisk/dockerskeletonENV FLASK_PROXY_PORT 8080###添加源文件添加requirements.txt/action/requirements.txt运行cd/action;点安装-r requirements.txt#将文件移到添加./main/action#重命名我们的可执行Python动作添加/main/main.py/action/execCMD ["/bin/bash",-c","cd actionProxy&& python -u actionproxy.py"] 

并确保您的Python代码接受来自stdin的Json供稿:

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

整个说明在这里: https://github.com/iainhouston/dockerPython

I have a simple Python program that I want to run in IBM Cloud functions. 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. 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

I've added the Docker container to IBM Cloud Functions like this:

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. 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?

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.

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:

# 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:

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

The whole explaination is here: https://github.com/iainhouston/dockerPython

这篇关于如何在IBM Cloud功能中运行docker映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆