如何使Python Docker镜像成为OpenWhisk操作?
我有一个运行Python程序的Docker镜像。 我现在想要运行这个容器作为OpenWhisk动作。 我该怎么做呢?
我已经看到了其他编程语言中的几个例子,以及C和Node.js中的一个优秀的黑盒子骨架方法。 但我想更多地了解OpenWhisk如何与容器交互,如果可能的话,只使用Python。
现在(9月2016)比我以前的答案简单得多。
使用$ wsk sdk install docker
命令创builddockerSkeleton
目录之后,您只需编辑Dockerfile
并确保您的Python(2.7现在)正在接受参数并以适当的格式提供输出。
这是一个总结。 我已经在GitHub上更详细地写了它
该程序
文件test.py
(或您将在下面编辑的Dockerfile
中使用的whatever_name.py
Dockerfile
)。
- 确保它是可执行的(
chmod a+x test.py
)。 - 确保它已经在第一线了。
- 确保它在本地运行。
- 例如
./test.py '{"tart":"tarty"}'
产生JSON字典:
{"allparams": {"tart": "tarty", "myparam": "myparam default"}}
- 例如
#!/usr/bin/env python import sys import json def main(): # accept multiple '--param's params = json.loads(sys.argv[1]) # find 'myparam' if supplied on invocation myparam = params.get('myparam', 'myparam default') # add or update 'myparam' with default or # what we were invoked with as a quoted string params['myparam'] = '{}'.format(myparam) # output result of this action print(json.dumps({ 'allparams' : params})) if __name__ == "__main__": main()
Dockerfile
将以下内容与提供的Dockerfile
进行比较,以获取Python脚本test.py
并准备好构buildDockerfile
镜像。
希望这些评论能够解释这些差异。 当前目录中的任何资产(数据文件或模块)将成为图像的一部分,在requirements.txt
列出的任何Python依赖项
# Dockerfile for Python whisk docker action FROM openwhisk/dockerskeleton ENV FLASK_PROXY_PORT 8080 # Install our action's Python dependencies ADD requirements.txt /action/requirements.txt RUN cd /action; pip install -r requirements.txt # Ensure source assets are not drawn from the cache # after this date ENV REFRESHED_AT 2016-09-05T13:59:39Z # Add all source assets ADD . /action # Rename our executable Python action ADD test.py /action/exec # Leave CMD as is for Openwhisk CMD ["/bin/bash", "-c", "cd actionProxy && python -u actionproxy.py"]
请注意ENV REFRESHED_AT ...
我用它来确保更新的test.py
图层被重新拾取,而不是在构build图像时从caching中绘制。
- 如何使用progrium / consul check-http脚本使用SERVICE_CHECK_HTTP?
- 使用yaourt和> makepkg-4.2.0自动构build并安装AUR for Arch Linux中的软件包
- 使用Docker我得到的错误:“SQLSTATE 没有这样的文件或目录”
- Pentaho + apache反向代理+代理SSL集成
- docker-compose错误,当我运行包
- 在Docker中使用Protobuf的Python“TypeError:无法将原始文件构build到描述符池中!
- 需要有关使用Dockersdevise应用程序和部署策略的体系结构的帮助
- IBM Container – su:无法创buildsubprocess:资源暂时不可用
- 使用来自Docker容器的PHP sendmail通过主机Postfix发送