I have a Docker image which runs a Python program. I want now to run this container as an OpenWhisk action. How do I do this?
I have seen several examples in other programming languages, and an excellent black box skeleton approach in C and Node.js. but I want to understand more about how OpenWhisk interacts with the container and, if possible, employ just Python.
It's a lot simpler now (Sept 2016) than in my previous answer.
After having created the
dockerSkeleton
directory with the command$ wsk sdk install docker
all you have to do is to edit theDockerfile
and make sure your Python (2.7 right now) is accepting parameters and supplying outputs in the appropriate format.Here's a summary. I've written it up in greater detail here on GitHub
The program
File
test.py
(orwhatever_name.py
you will use in your editedDockerfile
below.)chmod a+x test.py
)../test.py '{"tart":"tarty"}'
produces the JSON dictionary:
{"allparams": {"tart": "tarty", "myparam": "myparam default"}}
The Dockerfile
Compare the following with the supplied
Dockerfile
to take the Python scripttest.py
and ready it to build the docker image.Hopefully the comments explain the differences. Any assets (data files or modules) in the current directory will become part of the image as will any Python dependencies listed in
requirements.txt
Note the
ENV REFRESHED_AT ...
which I used to make sure that an updatedtest.py
layer is picked up afresh rather than being drawn from the cache when the image is built.