PROGRAMMING IOT
WITH DOCKER:
HOW TO START?
Mohd Syukor Abdul
Open Source Community
19 May 2017
Agenda
2
 What is IoT?
 What is Docker?
 Programming IoT with Docker?
What is IoT?
3
 https://www.postscapes.com/internet-of-things-award/open-source/
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
 In Malaysia: National Internet of Things (IoT) Strategic Roadmap
(http://mimos.my/iot/roadmap2.html)
What is IoT? (cont.)
6
 IoT Boards:
… and much more !!!
What is IoT? (cont.)
7
 IoT Sensors:
… and much more !!!
What is IoT? (cont.)
8
 IoT Gateways:
… and much more !!!
What is IoT? (cont.)
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.)
10
What is IoT? (cont.)
11
IoT Programming Languages:
 C/C++
 Python
 Java
 Javascript/NodeJS
 Lua
 .NET
 PHP
 HTML
 Go
 Assembly Language
 etc.
What is IoT? (cont.)
What is Docker?
12
 Docker is a platform for developing, shipping and running
applications using container virtualization technology.
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.
What is Docker? (cont.)
14
What is Docker? (cont.)
15
 The Docker Platform consists of multiple products/tools:
 Docker Engine
 Docker Registry
 Docker Machine
 Docker Swarm
 Docker Compose
 Kitematic
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/
What is Docker? (cont.)
17
The Docker way …
Programming IoT with Docker?
18
 Linux Distribution: Ubuntu Desktop 17.04 (amd64)
 Docker Version: Docker 17.05-ce
https://www.docker.com/community-edition
https://store.docker.com/search?type=edition&offering=community
https://mobyproject.org/
https://github.com/moby/moby/releases
Docker Installation
19
 https://store.docker.com/search?offering=community&type=edi
tion
 sudo apt-get -y install apt-transport-https ca-certificates
curl
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo apt-key add –
 sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs)
stable"
Docker Installation
20
 sudo apt update
 sudo apt-get -y install docker-ce
(OR)
 curl -fsSL https://get.docker.com/ | sh
 sudo usermod -aG docker $(whoami)
(for multi arch Docker)
 sudo apt install binfmt-support qemu-user-static
Docker Hub Registry
21
Development Environment
22
Boards USB Cable
Docker running
inside a computer
Enable USB Support for Docker
23
 Running docker cli with:
docker run …
--privileged
--device=/dev/ttyUSB0
-v /dev/bus/usb:/dev/bus/usb
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);
});
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
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
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 ...
Multi Arch Docker …
28
 Reference: https://docs.docker.com/docker-for-mac/multi-arch/
http://collabnix.com/archives/1778
Q & A
29
Thank you
30
https://www.slideshare.net/msyukor/presentations
Happy programming IoT
with Docker

Programming IoT with Docker: How to Start?

  • 1.
    PROGRAMMING IOT WITH DOCKER: HOWTO START? Mohd Syukor Abdul Open Source Community 19 May 2017
  • 2.
    Agenda 2  What isIoT?  What is Docker?  Programming IoT with Docker?
  • 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.)
  • 6.
    6  IoT Boards: …and much more !!! What is IoT? (cont.)
  • 7.
    7  IoT Sensors: …and much more !!! What is IoT? (cont.)
  • 8.
    8  IoT Gateways: …and much more !!! What is IoT? (cont.)
  • 9.
    9 IoT Platform: In simplewords 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.)
  • 10.
  • 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.
  • 14.
    What is Docker?(cont.) 14
  • 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/
  • 17.
    What is Docker?(cont.) 17 The Docker way …
  • 18.
    Programming IoT withDocker? 18  Linux Distribution: Ubuntu Desktop 17.04 (amd64)  Docker Version: Docker 17.05-ce https://www.docker.com/community-edition https://store.docker.com/search?type=edition&offering=community https://mobyproject.org/ https://github.com/moby/moby/releases
  • 19.
    Docker Installation 19  https://store.docker.com/search?offering=community&type=edi tion sudo apt-get -y install apt-transport-https ca-certificates curl  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • 20.
    Docker Installation 20  sudoapt update  sudo apt-get -y install docker-ce (OR)  curl -fsSL https://get.docker.com/ | sh  sudo usermod -aG docker $(whoami) (for multi arch Docker)  sudo apt install binfmt-support qemu-user-static
  • 21.
  • 22.
    Development Environment 22 Boards USBCable Docker running inside a computer
  • 23.
    Enable USB Supportfor Docker 23  Running docker cli with: docker run … --privileged --device=/dev/ttyUSB0 -v /dev/bus/usb:/dev/bus/usb
  • 24.
    Johnny-Five … 24 sudo dockerrun -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 pulltavk/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 ownrecipe … 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
  • 29.
  • 30.