Docker for Serverless Applications
eBook - ePub

Docker for Serverless Applications

  1. 250 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Docker for Serverless Applications

About this book

Build applications and infrastructures that leverage Function-as-a-Service and DockerAbout This Book• Implement containerization in Serverless/FaaS environments• Utilize Docker as a functional unit of work for Serverless/FaaS platforms• Use Docker as a portable infrastructure for Serverless ApplicationsWho This Book Is ForIf you are a Developer, a Docker Engineer, a DevOps Engineer, or any stakeholder interested in learning the use of Docker on Serverless environments then this book is for you.What You Will Learn• Learn what Serverless and FaaS applications are• Get acquainted with the architectures of three major serverless systems• Explore how Docker technologies can help develop Serverless applications• Create and maintain FaaS infrastructures• Set up Docker infrastructures to serve as on-premises FaaS infrastructures• Define functions for Serverless applications with Docker containersIn DetailServerless applications have gained a lot of popularity among developers and are currently the buzzwords in the tech market. Docker and serverless are two terms that go hand-in-hand.This book will start by explaining serverless and Function-as-a-Service (FaaS) concepts, and why they are important. Then, it will introduce the concepts of containerization and how Docker fits into the Serverless ideology. It will explore the architectures and components of three major Docker-based FaaS platforms, how to deploy and how to use their CLI. Then, this book will discuss how to set up and operate a production-grade Docker cluster. We will cover all concepts of FaaS frameworks with practical use cases, followed by deploying and orchestrating these serverless systems using Docker. Finally, we will also explore advanced topics and prototypes for FaaS architectures in the last chapter.By the end of this book, you will be in a position to build and deploy your own FaaS platform using Docker.Style and approachA practical guide that offers a simple way to easily understand Serverless Applications utilizing Docker as the development environment.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Docker for Serverless Applications by Chanwit Kaewkasi in PDF and/or ePUB format, as well as other popular books in Computer Science & Cloud Computing. We have over one million books available in our catalogue for you to explore.

Information

Putting Them All Together

In this chapter, we will walk through an example to demonstrate serverless platforms working together on a Docker cluster, and we will demonstrate several serverless/FaaS use cases.
We will discuss a mobile payment scenario and implement it using functions but, unusually at this level of infrastructure, we will connect all three FaaS platforms together. The main ideas demonstrated by the content of this chapter are the concept of using functions as a Glue, using functions to wrap the legacy web-based application, and using functions as a data stream processing program.
In the next section, we will start with the settings and scenario used by this chapter.
The topics covered in this chapter are:
  • A mobile payment scenario
  • A Parse platform as a backend
  • Preparing a WebHook in Fn
  • An event state machine with a blockchain
  • Wrapping a legacy with a function
  • Using a function as a Glue
  • A stream processor
  • Inter-FaaS platform networking

A mobile payment scenario

We are using a mobile payment with a money transfer allowed between two banks as the scenario for this chapter. With the money transfer, the business logic is easy to understand. So, we do not need to worry about this part. Let's focus on the complexity of the architecture.
Money transfer between two different banks with different underlying implementations is hard. This is because we cannot directly apply the concept of traditional transactions to cope with external systems. The system is presented in the following diagram:
Figure 8.1: The overall block diagram of the mobile payment system
What are we not covering in this chapter?
The UI parts are out beyond scope of this book, so they are not available. The Receipt Generator and the Receipt Storage are optional. They are left for you to implement, if interested.
What do we implement and demonstrate? Let's discuss:
  • The Parse platform, as a backend for the UI.
  • The Bank Routing function. It is written in Java and deployed on Fn. This component is called routing_fn.
  • Bank #1 and its function calling to a legacy web-based system. The function here is written in Node.js using the chromeless library (https://github.com/graphcool/chromeless). The function connects to a headless Chrome instance, our familiar web browser. The function drives Chrome to navigate and create a transaction for us on a real ERP system. We use Moqui as our ERP backend. Actually, Moqui comes with a complete set of REST APIs, but we intentionally use its web base to simulate the scenario where we need to modernize some legacy systems. The function of this part is called hivectl.
  • Bank #2 and its function, account_ctl, connecting to a REST-based bank system. The function is written using Go and will be running on OpenWhisk. The mock bank server behind this component is a simple one written using the Grails/Spring Boot framework. We use this component to demonstrate how to write a FaaS function to wrap and simplify a REST-based API. The Bank Routing function, routing_fn, will be selectively called by each bank. This Bank #2 component will be used together with Bank #1 there.
  • A set of smart contracts written in Solidity to maintain the mapping of mobile numbers to bank accounts. Also, another set of smart contracts will be used to maintain the state of the money transfer of each transaction.
  • An agent written in Java and the RxJava library to demonstrate a data stream processing component that calls a function and diverts the event to other parts of the system.

A Parse platform as a backend

What is Parse? Similar to Firebase, Parse is a Backend as a Service (BaaS) platform. With Parse, developers do not need to code the backend system themselves for their UIs or mobile applications. Parse is used by mobile application developers to help accelerate the development process. Together with the Parse dashboard, they provide an easy UI to craft all data entities, called classes, needed to process basic business logic.

Preparation

Here's how to create a Docker network and deploy a set of Docker compose files. We use the concept of metastack to deploy multiple stacks and have some labels and naming conventions to group them together:
$ docker network create \
--driver=weaveworks/net-plugin:2.1.3 \
--subnet=10.32.2.0/24 \
--attachable \
parse_net

$ docker volume create mongo_data

$ docker stack deploy -c mongodb.yml parse_01
$ docker stack deploy -c parse.yml parse_02
$ docker stack deploy -c parse_dashboard.yml parse_03
$ docker stack deploy -c ingress.yml parse_04
While deploying things on production, we do not set up the network and volumes with any Docker compose files. All stacks should refer to external volumes and networks.
Starting with MongoDB, we have already set up a volume for it. The following is the setup of the MongoDB server:
version: '3.3'

services:
mongo:
image: mongo:3.6.1-jessie
volumes:
- mongo_data:/data/db

volumes:
mongo_data:
external: true

networks:
default:
external:
name: parse_net
We move to the next component, the Parse platform. To make the container work with Træfik, we put some labels to the service, saying that it will be on the parse_net network and will expose port 1337 to Træfik's ingress.
We add a rule to allow every HTTP method, also to define the custom entrypoint, and allow Origin=* to enable the Parse dashboard, the next section, to be able to connect to the Parse server:
version: '3.3'

services:

parse_server:
image: parseplatform/parse-server:2.6.5
command: --appId APP1 --masterKey MASTER_KEY --databaseURI mongodb://mongo/prod
deploy:
labels:
- "traefik.docker.network=parse_net"
- "traefik.port=1337"
- "traefik.frontend.rule=Method: GET,POST,PUT,DELETE,OPTIONS,HEAD,CONNECT"
- "traefik.frontend.entryPoints=parse_server"
- "traefik.frontend.headers.customresponseheaders.Access-Control-Allow-Origin=*"

networks:
default:
external:
name: parse_net
Here's the Parse dashboard and its configuration. The current version of the dashboard is 1.1.2. It will be exposed to port 4040 via Træfik's ingress:
version: '3.3'

services:

parse_dashboard:
image: parseplatform/parse-dashboard:1.1.2
environ...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Serverless and Docker
  7. Docker and Swarm Clusters
  8. Serverless Frameworks
  9. OpenFaaS on Docker
  10. The Fn Project
  11. OpenWhisk on Docker
  12. Operating FaaS Clusters
  13. Putting Them All Together
  14. The Future of Serverless
  15. Other Books You May Enjoy