Function as a Service for Docker

Chanwit Kaewkasi
Jun 24, 2016 · 2 min read

I missed DockerCon live for its closing sessions but I saw a tweet from Jerome mentioning Ben Firshman about “Serverless” Docker.

Serverless Docker

And I really don’t know what does “Severless” mean. So I dig around and found it’s the Function-as-a-Service model. I studied this model a while ago to POC a Map-Reduce model (similar to Apache Spark) based on Docker but I made no progress.

Back to the example. Ben’s example is written in Python but I’m not a Python guy so I started looking around again. Ben pointed to Ahment’s go-dexec.

I forked and tweaked it a bit to fit my need and came up with this FaaS wrapper generator. I no-brainer call it `faas`.

With `faas get` you can generate a function from an image on Docker hub. But before you can generate the wrapper, you need to put a signature for your image. In case of Ben’s leftpad example, I have this Dockerfile inherited from his. I built and tagged it as chanwit/leftpad.

FROM bfirsh/leftpad

LABEL signature=”(string, int) error”

Try to prepare your own :-)

Next step is to generate the wrapper. You can do:

$ faas get docker.io/chanwit/leftpad

to generate a wrapper. Replace this with your own image. Currently I wrote a simple argument type mapper to map string and int just to make the demo work.

Then in test.go, you can just write:

package mainimport (
“fmt”
“docker.io/chanwit”
)
func main() {
err := chanwit.Leftpad(“foo”, 5)
if err != nil {
fmt.Println(err)
}
}

and run it with the command:

$ go run test.go

The program will trying to pull the image, spawn a container (on your cluster or node, depending on where you point DOCKER_HOST to), then run it. The current version of `faas` just prints something out. I’ll try to extend this and re-model the concept of Map-Reduce over it again. Hope it will be working this time. Pull requests are welcome!!

Check it out here:

https://github.com/chanwit/faas

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store