现在(2016年9月)比我以前的回答要简单得多。
dockerSkeleton使用命令创建目录后,$ wsk sdk install docker您要做的就是编辑,Dockerfile并确保您的Python(现在为2.7)接受参数并以适当的格式提供输出。
这是一个摘要。我已经在GitHub上更详细地写了它
文件test.py(或者whatever_name.py您将在Dockerfile下面的编辑中使用。)
chmod a+x test.py)。./test.py '{"tart":"tarty"}'{"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以获取Python脚本test.py并准备好构建docker映像。
希望这些评论可以解释这些差异。当前目录中的任何资产(数据文件或模块)都将成为映像的一部分,而requirements.txt
# 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"]
Run Code Online (Sandbox Code Playgroud)
注意ENV REFRESHED_AT ...,我用来确保test.py在构建图像时重新拾取更新的图层,而不是从缓存中绘制该图层。
| 归档时间: |
|
| 查看次数: |
698 次 |
| 最近记录: |