Docker is a container-based platform that is able to host one or more components (such as databases, services, or queues) in a single bundle. Docker is similar to a virtual machine (VM) but instead of emulating hardware, it shares the operating system and libraries with the host machine. For this reason, Docker is more similar to a dedicated environment than to a VM. Other container-based technologies are available in the market, such as LXC or open container initiative (OCI), and it is likely that over the next few years we will see these technologies develop massively. For now, however, Docker is the standard technology used to develop microservices using container-based architecture.
Docker offers the great advantage of allowing us to build a container from a legacy application so we can port old applications into a new microservice-based ecosystem with very few changes. Docker has become so popular in the past few years that today it is not only used for porting old technologies, but also for building new ones. For instance, some authors use Docker to build analytics.
Let's consider an example. Imagine you have an old legacy application developed in FORTRAN with a reading file for input, a file database for parameters, and a writing file for output. You want to deploy this application as a scalable service. You can build your Docker container by packaging together all of the different elements and exposing it as a service in your infrastructure.
The following code runs a local Python HTTP server on your machine. Install Docker Community Edition from https://store.docker.com/, then create a local directory; create a file called Dockerfile; Finally copy into the file the following command-line instructions:
FROM alpine
# Install python3
RUN apk add --update python3
# Copy html
RUN mkdir /src
ADD static/ /src
RUN cd /src
# Run http server on port 8080
EXPOSE 8080
CMD ["python3", "-m", "http.server", "8080"]
From the command console, you have to build a simple HTML page called index.html:
mkdir static
echo "<html><body>I-IoT</body></html>" > static/index.html
Now follow these steps:
- Build your Docker container with the following command:
docker build --tag micropy .
- Run your Docker container:
docker run -p 80:8080 micropy
- Open your browser to http://localhost/src or http://<your ip address>/src
Here's a list of the most common Docker commands:
docker run <image> |
Runs the container |
docker ps |
Lists the containers |
docker stop <id> |
Stops the containers |
docker rm <id> |
Removes the container |
docker exec … |
Attaches to the container |
docker build . |
Builds the container |
We have now built our first Docker microservice. On the Dockerfile, we provided the following instructions to Docker:
- Use the alpine image
- Install Python 3
- Create a local src directory
- Copy on the local directory the content you can find on the static local folder
- Run the Python server
We then run the command to build the container and start mapping from port 8080 to 80. The most important thing is being able to build a container from a simple script written on the Dockerfile.
These technologies need an orchestrator to allocate resources and manage scalability. Some of the most common solutions are Kubernetes, Swarm, EC2, GCC, and Mesos. When we talk about containers, we are referring to Container as a Service (CaaS). We will explore these technologies later.
If you do not want to use Docker and you want to develop your own microservice, the following table provides a list of the most common technologies used to build microservices:
Technology |
Purpose |
Spring Boot |
Service |
Node.js |
UI |
NGNIX |
UI, balancing |
Python |
Analytic |
Golang |
Service |
.NET |
UI, service |
Docker |
Container |
If you need an orchestrator, you can use native cloud capabilities or an agnostic framework, such as Cloud Foundry (CF).
In a typical software system, we have to consider five important steps: development, deployment, operation, maintenance, and enhancement. The final two, maintenance and enhancement, are the most difficult elements in I-IoT. Developers are often asked by their business department to implement small functionalities quickly, or to build workarounds to manage a particularly difficult device or asset.
Recently, Amazon and Oracle have proposed serverless technologies. The basic idea of these is to provide the developer with the ability to build and deploy a function. In other words, the developer can build their own function and deploy it in a single click, without having to redeploy the entire microservice. Serverless technologies can be considered an extreme version of microservices. When we speak about functions, we refer to Function as a Service (FaaS) see the following table. We will discover serverless technologies, such as AWS or Predix or Azure or GCP, in Chapter 9, Understanding Industrial OEM Platforms, Chapter 10, Implementing a Cloud Industrial IoT Solution with AWS, Chapter 11, Implementing a Cloud Industrial IoT Solution with Google Cloud, and Chapter 12, Performing a Practical Industrial IoT Solution with Azure:
Cloud orchestrators |
Function |
Infrastructure as a Service (IaaS) |
Provides access to a resource (CPU, memory, OS) on a virtualized environment. |
Platform as a Service (PaaS) |
Provides an environment to build applications and services for the developer. |
Service as a Service (SaaS) |
Provides access to services and applications ready to be used. |
Backend as a Service (BaaS) |
A computing service model that serves as the middleware that provides developers the ability to connect applications to cloud services through the API or SDK. |
Data as a Service (DaaS) |
An extension of SaaS where content and data, such as wheat-ear, city traffic, or statistics, are provided as a service. |
Container as a Service (CaaS) |
An extension of PaaS where the developer can deploy container-based applications. |
Function as a Service (FaaS) |
An extension of PaaS where the developer can build a small function without worrying about the application server or the OS. |
X as a Service(XaaS) |
Anything as a service. It is a way to generalize the concept of as a service. |
These technologies are not strictly related to IoT or I-IoT, but they provide a good point of reference for implementing an I-IoT application.