Test Driving Docker Function as a Service (FaaS)

Explore Docker Function as a Service (FaaS) and learn how it combines serverless computing with Docker's flexibility. Discover the benefits, setup steps, and use cases for deploying serverless functions in Docker containers.

Test Driving Docker Function as a Service (FaaS)

Serverless is no longer just a buzzword for Docker; it is now a reality. Recently, I had the opportunity to test drive the Docker Serverless project, better known as Docker FaaS (Functions as a Service).

Fellow Docker Captain Alex Ellis is the mastermind behind the project. Docker FaaS started back in December '16 and I started following the project with excitement shortly after.

Since then it has made its way into the popular tech news site of Infoworld and gathered impressive feedback from Hacker News. The Docker FaaS project has reached and then surpassed 1,000 GitHub stars while I was writing this article.

Impressive!

What is Serverless / FaaS

I detailed the Serverless space back in November '16 in The Insiders Guide to Docker Serverless. Since then the FaaS space has grown substantially from tooling to additional projects.

But for a quick definition, Wikipedia describes FaaS as:

"FaaS is a category of cloud computing services that provides a platform allowing customers to develop, run, and manage application functionalities without the complexity of building and maintaining the infrastructure typically associated with developing and launching an app"

In other words, FaaS makes it dead simple to deploy a highly scalable and cost-efficient application. With just a few lines of code no need to worry about infrastructure or development boilerplates. Making a FaaS simple to use with good integrations is where the magic is.

Tell me about Docker FaaS

So you might ask yourself why I chose Docker FaaS over the other available frameworks. I'm glad you asked. The features that persuaded me were:

  1. Integrates directly with Docker Swarm
  2. Built-in Prometheus metrics
  3. Any container can become a function
  4. Autoscaling
  5. Ease of use, a one-line script starts everything
  6. Can launch new functions directly from UI
  7. Integrate with other services via WebHooks like GitHub

Docker FaaS has two main components: the API Gateway and Function Watchdog.

The API Gateway is responsible for routing external traffic to the functions, collecting metrics for Prometheus, and autoscaling functions via Docker Swarm replicas. FaaS includes a clean UI that allows you to invoke functions and create new functions as needed.

The Function Watchdog runs inside each container. The Watchdog marshalls HTTP requests between the public HTTP URL the target function.

What's unique about Docker FaaS is that it runs one replica of your function all the time. This enables Docker FaaS to have lightning-fast response times when a function is triggered.

Other projects require the trigger of the function to provision a new replica for each trigger. This action consumes precious start time before the function can be executed. When the time to execution matters, Docker FaaS is the clear leader.

Docker FaaS Review

My first impression of the Docker FaaS is how dead simple it is to launch the entire FaaS stack. Once the stack is up and running, the clean and simple UI will reveal about 10 sample functions installed by default. These functions range from simple word counting to querying the Docker Hub for Repos.

Docker FaaS UI

When you click on a function, the UI opens the function and provides the ability to invoke it directly. It's possible to pass either Text or JSON to the function and click the Invoke button, which triggers the function and responds with an output.

Creating new functions is available at the click of a button. Once you click Create New Function. It is easy to define a new function. Alex made an excellent boilerplate image functions/alpine , a great starting point for new functions. This image makes it easy to turn any UNIX process into a function. I chose to use sha256sum it for my demo.

Create FaaS Function

Next, I called the newly created function via the curl command.

curl <ip of Docker host>:8080/function/hash -d "hi"; done

This passed "hi" to the function, which then returned the hash value as the output. If desired, it is also possible to pass "hi" directly via the UI. It works exactly the same.

Autoscaling

Testing the autoscaling capability was very straightforward. Engaging autoscaling was as easy as passing a loop to the newly created hash function.

while [ true ] ; do sleep 0.3 && curl <ip of Docker host>:8080/function/hash -d "hi"; done 

After the loop runs for a minute or two, you will notice the Invocation Count increase in the UI. Eventually, the number of replicas will scale in increments of 5 and then 10. See the screenshots below of the FaaS UI, the Prometheus graph, and Grafana of how the replicas are scaling with the load.

Docker FaaS Conclusion

From the moment I began testing till now, Alex has improved Autoscaling, UI improvements, and countless other features. I was so impressed with the initial tests that I presented Docker FaaS at two different meetups: Operationalizing Containers and ETH Polymese.

Here are the slides from the presentations for Docker Serverless. Now, I'm working on how we can integrate this into some development projects and assist Alex with some testing and documentation.

A lot of momentum is building around Docker FaaS. I would encourage everyone to head over to the project page https://github.com/alexellis/faas and try it out, contribute, and provide feedback to the FaaS.

FAQ Section: Test Driving Docker Function as a Service (FaaS)

What is Docker Function as a Service (FaaS), and how does it work?
Docker Function as a Service (FaaS) is a serverless computing model that allows you to run functions in response to events without managing the underlying infrastructure. In Docker FaaS, functions are packaged in containers, which are executed on demand. This model combines the flexibility of Docker with the scalability of serverless architecture, enabling you to deploy and manage functions efficiently.

How does Docker FaaS differ from traditional serverless platforms?
Docker FaaS differs from traditional serverless platforms by offering more control over the environment in which functions run. While traditional platforms like AWS Lambda use predefined runtimes, Docker FaaS allows you to define your runtime environment within a Docker container. This flexibility lets you use any programming language, libraries, or dependencies that you can package in a container, making it easier to port functions across different environments.

What are the benefits of using Docker for FaaS?
Using Docker for FaaS offers several benefits, including greater control over the runtime environment, portability across different cloud providers or on-premises systems, and the ability to easily test and debug functions locally. Docker also allows you to maintain consistency between development and production environments, reducing the risk of deployment issues. Additionally, Docker FaaS can be more cost-effective by only running functions when needed.

How can I get started with Docker FaaS?
To get started with Docker FaaS, you can use frameworks like OpenFaaS or Fn Project, which enable you to deploy serverless functions in Docker containers. First, install the chosen framework on your system, then create a function and package it in a Docker container. Deploy the function using the framework’s tools, and trigger it using HTTP requests, events, or schedules. Testing locally with Docker Compose before deploying to production helps ensure everything works as expected.

What are some use cases for Docker FaaS?
Docker FaaS can be used in a variety of scenarios, including building microservices, processing data streams, automating tasks, and running event-driven applications. It’s particularly useful for workloads that require flexibility in the runtime environment or need to be portable across different platforms. Docker FaaS also suits environments where you want to minimize infrastructure management while still maintaining control over how functions are packaged and executed.

Follow me

If you liked this article, Follow Me on Twitter to stay updated!