This document discusses programming IoT devices with Docker. It begins with an overview of IoT and Docker, defining IoT as connecting devices over the internet and Docker as a platform for developing and running containerized applications. It then provides examples of programming IoT boards, sensors and gateways using Docker containers, including with Johnny-Five for Node.js, ESP32, Apache MyNewt, and building custom images. It emphasizes that Docker allows building once and running anywhere through isolated, portable containers.
3. What is IoT?
3
https://www.postscapes.com/internet-of-things-award/open-source/
4. What is IoT? (cont.)
4
According to Gartner, the Internet of Things will balloon to
26 billion devices by 2020.
There’s big money in these little devices: Gartner projects
IoT will result in $1.9 trillion in global economic “value-
add”—the combined benefits that businesses derive through
the sale and usage of IoT technology.
http://www.gartner.com/newsroom/id/2636073
5. 5
In Malaysia: National Internet of Things (IoT) Strategic Roadmap
(http://mimos.my/iot/roadmap2.html)
What is IoT? (cont.)
9. 9
IoT Platform:
In simple words the purpose of any IoT device is to connect
with other IoT devices and applications (cloud-based mostly)
to relay information using internet transfer protocols.
The gap between the device sensors and data networks is
filled by an IoT Platform. Such a platform connects the data
network to the sensor arrangement and provides insights
using backend applications to make sense of plethora of data
generated by hundreds of sensors.
Example: Amazon Web Services (AWS) IoT, Microsoft Azure
IoT, Thinger.IO, ThingsBoard, Kaa IoT Platform, etc.
What is IoT? (cont.)
11. 11
IoT Programming Languages:
C/C++
Python
Java
Javascript/NodeJS
Lua
.NET
PHP
HTML
Go
Assembly Language
etc.
What is IoT? (cont.)
12. What is Docker?
12
Docker is a platform for developing, shipping and running
applications using container virtualization technology.
13. What is Docker? (cont.)
13
Using containers, everything required to make a piece of
software run is packaged into isolated containers.
Unlike VMs, containers do not bundle a full operating
system - only libraries and settings required to make the
software work are needed.
This makes for efficient, lightweight, self-contained
systems and guarantees that software will always run the
same, regardless of where it’s deployed.
15. What is Docker? (cont.)
15
The Docker Platform consists of multiple products/tools:
Docker Engine
Docker Registry
Docker Machine
Docker Swarm
Docker Compose
Kitematic
16. What is Docker? (cont.)
16
docker info # Displays system wide information of Docker
docker build # Build an image from a Dockerfile
docker images # List all images on a Docker host
docker pull # Pull an image from a Registry
docker run # Run an image
docker ps # List all running and stopped instances
docker stop # Stop a running instances
docker rm # Remove an instance
docker rmi # Remove an image
docker stats # Show running containers‘ resource usage info
docker attach # Attach to a running container
docker logs # Fetch the logs of a container
docker inspect # Return low-level information on a container
docker history # Show the history of an image
https://docs.docker.com/engine/reference/commandline/docker/
23. Enable USB Support for Docker
23
Running docker cli with:
docker run …
--privileged
--device=/dev/ttyUSB0
-v /dev/bus/usb:/dev/bus/usb
24. Johnny-Five …
24
sudo docker run -ti --privileged node /bin/bash
(in container)
npm install johnny-five
node helloworld.js
// file: helloworld.js
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a standard `led` component instance
var led = new five.Led(13);
// "blink" the led in 1500ms
// on-off phase periods
led.blink(1500);
});
25. ESP32 …
25
docker pull tavk/esp32-sdk:0.1.0
sudo docker run -t -i -u esp
-v /home/user1/esp-
idf/examples/01_hello_world:/home/esp/shared_project
tavk/esp32-sdk:0.1.0
make all
sudo docker run -t -i -u esp
--device=/dev/ttyUSB0
-v /home/user1/esp-
idf/examples/01_hello_world:/home/esp/shared_project
tavk/esp32-sdk:0.1.0
make flash
Reference: https://github.com/T-vK/docker-esp-sdk/tree/esp32
26. Apache MyNewt …
26
#!/bin/bash
if [ "$1" = "debug" ] || [ "$1" = "run" ]
then
ti="-ti"
fi
docker run -e NEWT_USER=$(id -u) -e NEWT_GROUP=$(id -g) -e
NEWT_HOST=$(uname) $ti --rm --device=/dev/bus/usb --privileged -v
$(pwd):/workspace -w /workspace mynewt/newt:latest /newt "$@"
Reference: https://mynewt.incubator.apache.org/latest/os/get_started/docker/
https://mynewt.incubator.apache.org/latest/os/tutorials/arduino_zero/
bash file:
newt
cd myproject
../newt version
27. Build your own recipe …
27
Use Dockerfile and build your own new image
Look into others Dockerfile from Docker Hub Registry, improved it
and start build your own images …
mkdir myspecial1
cd myimage
nano Dockerfile
docker build -t myspecial1 .
docker run --privileged -v /dev/bus/usb:/dev/bus/usb
myspecial1 ...
28. Multi Arch Docker …
28
Reference: https://docs.docker.com/docker-for-mac/multi-arch/
http://collabnix.com/archives/1778