Docker Guide: Difference between revisions

From Variscite Wiki
No edit summary
 
(22 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use RELEASE_THUD_V1.0_VAR-SOM-MX6 as default
<!-- Set release according to "release" parameter in URL and use RELEASE_THUD_V1.0_VAR-SOM-MX6 as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!--
--> {{INIT_RELEASE_PARAM|RELEASE_THUD_V1.0_VAR-SOM-MX6}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_THUD_V1.0_VAR-SOM-MX6}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Docker}} {{DocImage|category1=Yocto|category2={{#var:HARDWARE_NAME}}}} __toc__
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--  
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#vardefine:GUIDE_NAME|{{#if: {{#var:B2QT_GIT}} | B2QT | Yocto }}}} <!--
--> {{#vardefine:DOCKER_INTEGRATION_PREFIX|{{#varexists:DEBIAN_NAME | DEBIAN_ |}}}} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Docker}} {{DocImage|category1=Yocto|category2=Debian}} <!--
--> {{VAR_FILES_DOMAIN}} <!--
--> [[category:{{#var:HARDWARE_NAME}}]] __toc__


= Docker Introduction =
= Docker Introduction =
 
Docker is a software platform that allows the creation, testing and distribution of applications via containers.<br>
Docker is an application that simplifies the process of managing application processes in containers.<br>
Containers let you run your applications in resource-isolated processes. There are some similarities to virtual machines, but  
Containers let you run your applications in resource-isolated processes. They’re similar to virtual machines, but containers<br>
containers are more portable, more resource-friendly, and enables faster software delivery cycles.<br>
are more portable, more resource-friendly, and more dependent on the host operating system.<br>
Often used with docker there's a companion tool known as docker-compose: compose is used for defining and running multi-container Docker applications.<br>
<br>
<br>
You can check Docker online documentation at:<br>
You can check Docker online documentation at:<br>
https://docs.docker.com/get-started/<br>
https://docs.docker.com/get-started/<br>
https://docs.docker.com/compose/<br>
https://training.play-with-docker.com/<br>
https://training.play-with-docker.com/<br>
https://docker-curriculum.com/<br>
https://docker-curriculum.com/<br>


= Yocto Integration =
{{#switch: {{#var:SOC_SERIES}}
 
| am6=
== Recipe ==
|#default=
 
{{{{#var:DOCKER_INTEGRATION_PREFIX}}DOCKER_INTEGRATION}}
Before you begin, get familiar with the Varicite {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} guide.<br>
<br>
Variscite provides a light reference image with Docker, var-image-docker.<br>
This image is based on the core-image bbclass with the addition of a few more packages and features:
* docker{{#ifeq: {{#var:YOCTO_NAME}}|Thud||-ce}}
* python3-docker-compose
* ssh-server-dropbear
* basic command line tools
 
== Create a Docker-ready Image ==
* Follow steps 1-3 of the {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} page.
$ cd {{#var:BUILD_FOLDER}}
{{#ifeq: {{#var:SOC_SERIES}} | imx8 |
$ MACHINE={{#var:MACHINE_NAME}} DISTRO={{#var:BUILD_DISTRO}} {{#var:BUILD_SCRIPT}} -b {{#var:BUILD_FOLDER_XWAYLAND}}
|
$ MACHINE={{#var:MACHINE_NAME}} DISTRO={{#var:BUILD_DISTRO}} {{#var:BUILD_SCRIPT}} {{#var:BUILD_FOLDER_X11}}
}}
}}
Append the following to the conf/local.conf file in your Yocto build directory:
DISTRO_FEATURES_append = " virtualization"
$ bitbake var-image-docker


= Test Docker =
= Test Docker =
* Check target Internet connection<br>
* Check docker version:<br>
  root@{{#var:MACHINE_NAME}}:~# ping 8.8.8.8
root@{{#var:MACHINE_NAME}}:~# docker --version


* Get the target IP address.<br>
== Test hello-world ==
* Open ssh terminal from host:<br>
  ssh root@<ip address>


* Check docker version.<br>
* Pull the hello-world image from Docker Hub:<br>
  root@{{#var:MACHINE_NAME}}:~# docker --version<br>
root@{{#var:MACHINE_NAME}}:~# docker pull hello-world
  Docker version 18.09.3{{#ifeq: {{#var:YOCTO_NAME}}|Thud||-ce}}, build f5e591e
 
== Test hello-world ==
root@{{#var:MACHINE_NAME}}:~# docker pull hello-world<br>
Using default tag: latest<br>
latest: Pulling from library/hello-world<br>
256ab8fe8778: Pull complete <br>
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e<br>
Status: Downloaded newer image for hello-world:latest


* List docker images:<br>
* List docker images:<br>
  root@{{#var:MACHINE_NAME}}:~# docker images<br>
root@{{#var:MACHINE_NAME}}:~# docker images
  REPOSITORY          TAG                IMAGE ID            CREATED            SIZE<br>
  hello-world        latest              a29f45ccde2a        3 months ago        9.14kB


* Run hello-world:<br>
* Run hello-world container:<br>
  root@{{#var:MACHINE_NAME}}:~# docker run hello-world
root@{{#var:MACHINE_NAME}}:~# docker run hello-world
   
   
  Hello from Docker!<br>
Hello from Docker!<br>
  This message shows that your installation appears to be working correctly.
This message shows that your installation appears to be working correctly.
   
   
  To generate this message, Docker took the following steps:<br>
To generate this message, Docker took the following steps:<br>
  1. The Docker client contacted the Docker daemon.<br>
  1. The Docker client contacted the Docker daemon.<br>
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.<br>
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.<br>
      (arm64v8)<br>
  3. The Docker daemon created a new container from that image which runs the<br>
  3. The Docker daemon created a new container from that image which runs the<br>
    executable that produces the output you are currently reading.<br>
      executable that produces the output you are currently reading.<br>
  4. The Docker daemon streamed that output to the Docker client, which sent it<br>
  4. The Docker daemon streamed that output to the Docker client, which sent it<br>
    to your terminal.
      to your terminal.


== Test Ubuntu ==
== Test Ubuntu ==
root@{{#var:MACHINE_NAME}}:~# docker pull ubuntu<br>
* Pull the ubuntu image from Docker Hub:<br>
Using default tag: latest<br>
root@{{#var:MACHINE_NAME}}:~# docker pull ubuntu
latest: Pulling from library/ubuntu<br>
 
b2f61026a351: Pull complete<br>
* Run ubuntu:<br>
5538fb30c42c: Pull complete<br>
root@{{#var:MACHINE_NAME}}:~# docker run -it ubuntu<br>
f0b05810781a: Pull complete<br>
root@8637148015f5:/# apt update<br>
0180a33352d6: Pull complete<br>
<br>
Digest: sha256:bec5a2727be7fff3d308193cfde3491f8fba1a2ba392b7546b43a051853a341d<br>
root@8637148015f5:/# apt install nodejs<br>
Status: Downloaded newer image for ubuntu:latest
<br>
root@8637148015f5:/# node -v<br>
<br>
root@8637148015f5:/# exit<br>
root@{{#var:MACHINE_NAME}}:~#
 
= Test docker-compose =
* Check the docker-compose version:<br>
root@{{#var:MACHINE_NAME}}:~# docker-compose --version


* List docker images:<br>
== Examples ==
  root@{{#var:MACHINE_NAME}}:~# docker images
 
  REPOSITORY          TAG                IMAGE ID            CREATED            SIZE
=== RESTful-based data-logger ===
  ubuntu              latest              428b2f74b0fb        2 weeks ago        57.7MB
 
  hello-world        latest              a29f45ccde2a        3 months ago        9.14kB
This [{{#var:VAR_FILES_HTTPS}}/docker/Docker_Example01_RestDataLogger.zip archive] provides an example of a RESTful-based data-logger to be deployed on an embedded device acting as an intelligent edge node in large connected networks.<br>
Through a developed web service application based on the ''Tornado web framework'', data can be easily inserted and retrieved from a ''MongoDB'' instance by remote devices.


* Run ubuntu:<br>
In the tutorial the application is proposed as a '''Docker'''-based solution in which each component is run in a separate container.<br>
  root@{{#var:MACHINE_NAME}}:~# docker run -it ubuntu<br>
'''Docker Compose''' is used to simplify the build of custom Docker images, their deployment, and configuration.<br>
  root@8637148015f5:/# apt update<br>
The application can be easily tested on any device which supports Docker and Docker Compose, be it a PC or an embedded device.
  .................................<br>
  Fetched 16.3 MB in 11s (1471 kB/s)<br>                                                                                                             
  Reading package lists... Done<br>
  Building dependency tree<br>
  Reading state information... Done<br>
  12 packages can be upgraded. Run 'apt list --upgradable' to see them.


  root@8637148015f5:/# apt install nodejs<br>
=== PyQt application ===
  Reading package lists... Done<br>
  Building dependency tree<br>
  Reading state information... Done<br>
  The following additional packages will be installed:<br>
    ca-certificates libc-ares2 libhttp-parser2.7.1 libicu60 libnghttp2-14 libssl1.0.0 libssl1.1 libuv1 nodejs-doc openssl<br>
  The following NEW packages will be installed:<br>
    ca-certificates libc-ares2 libhttp-parser2.7.1 libicu60 libnghttp2-14 libssl1.0.0 libssl1.1 libuv1 nodejs nodejs-doc openssl<br>
  0 upgraded, 11 newly installed, 0 to remove and 12 not upgraded.<br>
  Need to get 15.6 MB of archives.<br>
  After this operation, 62.8 MB of additional disk space will be used.<br>
  Do you want to continue? [Y/n] y<br>
  ...........................................<br>
  Updating certificates in /etc/ssl/certs...<br>
  0 added, 0 removed; done.<br>
  Running hooks in /etc/ca-certificates/update.d...<br>
  done.<br>


  root@8637148015f5:/# node -v<br>
This [{{#var:VAR_FILES_HTTPS}}/docker/Docker_Example02_PyQtApplication.zip archive] provides a PyQt reference application . The Wayland graphic server is abstracted as resource to be passed to a Docker image in which the application is deployed.
  v8.10.0<br>
  root@8637148015f5:/# exit<br>


= Test docker-compose =
In the Dockerfile the reference buster-slim image is used as a starting point, then python3 and all dependencies necessary to execute Qt applications are installed. Wayland backend has been chosen because the only one available for all Variscite SoMs.
* Check the docker-compose version:<br>
  root@{{#var:MACHINE_NAME}}:~# docker-compose --version<br>
  docker-compose version 1.21.2, build e7de1bc<br>


== Example 1: a RESTful-based data-logger
=== GStreamer application ===


The linked file [[File:Docker_Example01_RestDataLogger.zip]] provides an example of a RESTful-based data-logger to be deployed on an embedded device acting as an intelligent edge node in large connected networks. Through a developed Web service application based on the ''Tornado web framework'', data can be easily inserted and retrieved from a ''MongoDB'' instance by remote devices.
This [{{#var:VAR_FILES_HTTPS}}/docker/Docker_Example03_GStreamer.zip archive] provides a Gstreamer test application . The Wayland graphic server is abstracted as resource to be passed to a Docker image in which the application is deployed.


In the tutorial the application is proposed as a '''Docker'''-based solution in which each component is a separate container.  
In the Dockerfile the reference buster-slim image is used as a starting point, then gstreamer1.0 and all dependencies necessary to execute GStreamer applications are installed. Wayland backend has been chosen because the only one available for all Variscite SoMs.
'''Docker Compose''' is used to simplify the build of custom Docker images, their deployment, and configuration. The application can be easily tested on personal computers and embedded devices supporting Docker and Docker Compose.

Latest revision as of 13:41, 1 December 2023

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release RELEASE_THUD_V1.0_VAR-SOM-MX6.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
VAR-SOM-MX6 - Docker

Docker Introduction

Docker is a software platform that allows the creation, testing and distribution of applications via containers.
Containers let you run your applications in resource-isolated processes. There are some similarities to virtual machines, but containers are more portable, more resource-friendly, and enables faster software delivery cycles.
Often used with docker there's a companion tool known as docker-compose: compose is used for defining and running multi-container Docker applications.

You can check Docker online documentation at:
https://docs.docker.com/get-started/
https://docs.docker.com/compose/
https://training.play-with-docker.com/
https://docker-curriculum.com/

Yocto Integration

Recipe

Before you begin, get familiar with the Yocto Build Release guide.

The Yocto BSP provides 2 dedicated images:

  • var-image-docker: a graphic enabled image based on fsl-image-gui with the addition of a few more packages:
    • docker
    • python3-docker-compose
  • var-image-docker-minimal: a console image based on the core-image bbclass with the addition of a few more packages and features:
    • docker
    • python3-docker-compose
    • ssh-server-dropbear
    • basic command line tools

Create a Docker-ready Image

$ cd ~/var-fslc-yocto
$ MACHINE=var-som-mx6 DISTRO=fslc-x11 . setup-environment build_x11

Append the following to the conf/local.conf file in your Yocto build directory:

DISTRO_FEATURES_append = " virtualization"

Build var-image-docker:

$ bitbake var-image-docker

Test Docker

  • Check docker version:
root@var-som-mx6:~# docker --version

Test hello-world

  • Pull the hello-world image from Docker Hub:
root@var-som-mx6:~# docker pull hello-world
  • List docker images:
root@var-som-mx6:~# docker images
  • Run hello-world container:
root@var-som-mx6:~# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

Test Ubuntu

  • Pull the ubuntu image from Docker Hub:
root@var-som-mx6:~# docker pull ubuntu
  • Run ubuntu:
root@var-som-mx6:~# docker run -it ubuntu
root@8637148015f5:/# apt update

root@8637148015f5:/# apt install nodejs

root@8637148015f5:/# node -v

root@8637148015f5:/# exit
root@var-som-mx6:~#

Test docker-compose

  • Check the docker-compose version:
root@var-som-mx6:~# docker-compose --version

Examples

RESTful-based data-logger

This archive provides an example of a RESTful-based data-logger to be deployed on an embedded device acting as an intelligent edge node in large connected networks.
Through a developed web service application based on the Tornado web framework, data can be easily inserted and retrieved from a MongoDB instance by remote devices.

In the tutorial the application is proposed as a Docker-based solution in which each component is run in a separate container.
Docker Compose is used to simplify the build of custom Docker images, their deployment, and configuration.
The application can be easily tested on any device which supports Docker and Docker Compose, be it a PC or an embedded device.

PyQt application

This archive provides a PyQt reference application . The Wayland graphic server is abstracted as resource to be passed to a Docker image in which the application is deployed.

In the Dockerfile the reference buster-slim image is used as a starting point, then python3 and all dependencies necessary to execute Qt applications are installed. Wayland backend has been chosen because the only one available for all Variscite SoMs.

GStreamer application

This archive provides a Gstreamer test application . The Wayland graphic server is abstracted as resource to be passed to a Docker image in which the application is deployed.

In the Dockerfile the reference buster-slim image is used as a starting point, then gstreamer1.0 and all dependencies necessary to execute GStreamer applications are installed. Wayland backend has been chosen because the only one available for all Variscite SoMs.