跳转至

Docker容器支持#

从8.0版开始,Docker映像支持X64、Arm和Arm64架构。

要设置的变量#

名称 类型 可能的值 默认 描述
CONNECT_IOT_MANAGER_NAME 字符串 自动化管理器ID
CONNECT_IOT_MONITOR_HOSTNAME 字符串 localhost 运行管理器的服务器的名称。仅当驱动和控制器在不同的管理器中运行时才需要
CONNECT_IOT_REPOSITORY_TYPE 字符串 Npm
Directory
Npm 用于检索二进制文件包的代码库的类型
CONNECT_IOT_REPOSITORY_LOCATION 字符串 代码库的位置(网址或目录路径)
CONNECT_IOT_STORAGE_RETENTION_TIME 整型\字符串 30d 保留持久值的时间
TENANT_NAME 字符串 主机的租户
DISCOVERY_SERVICES_URL_SUFFIX 字符串 负载均衡器的后缀
DISCOVERY_SERVICES_ENABLED 布尔值 false 负载均衡模块是否正在运行
APPLICATION_PUBLIC_HTTP_ADDRESS 字符串 主机正在侦听的地址
APPLICATION_PUBLIC_HTTP_PORT 整数 80 主机的端口
APPLICATION_PUBLIC_HTTP_TIMEOUT 整数 60000 用于系统调用的超时
APPLICATION_AUTHENTICATION_TYPE 字符串 Password
SecurityPortal
密码 用于访问主机的身份验证模式
APPLICATION_AUTHENTICATION_DOMAIN 字符串 处于Password模式下时,该变量为用户所在的网域
APPLICATION_AUTHENTICATION_USERNAME 字符串 处于Password模式下时,该变量为用户名
APPLICATION_AUTHENTICATION_PASSWORD 字符串 处于Password模式下时,该变量为密码
APPLICATION_ACCESS_TOKEN 字符串 处于SecurityPortal模式下时,该变量为访问令牌
APPLICATION_PUBLIC_HTTP_TLS_ENABLED 布尔值 false 主机是否在SSL模式下运行
SECURITY_PORTAL_CLIENT_ID 字符串 处于SecurityPortal模式下时,该变量为客户端的ID
SECURITY_PORTAL_PUBLIC_URL 字符串 处于SecurityPortal模式下时,

特殊路径#

以下路径在容器中是硬编码的,但如果要更好地控制该行为,可以通过创建映像来覆盖硬编码的路径。

路径 描述
/usr/iot/ 物联网模块根目录
/usr/iot/manager/config.json 使用定义的环境变量生成的配置文件
/usr/iot/cache 缓存的位置(已下载并经过验证的运行时包)
/usr/iot/persistency 将放置持久性日期的位置。Ramark:如果整个内容都保存在容器内,则在移除容器时整个内容都将丢失。
/usr/iot/logs 日志的写入位置。Ramark:如果将整个内容保存在容器内,则移除容器时,整个内容将丢失。

包括的配置文件#

这是原始配置文件。将使用定义为环境变量的相应值自动预处理该配置文件以包括占位符的值。

{
 "id": "${CONNECT_IOT_MANAGER_NAME}",
 "cache": "/usr/iot/cache",
 "hostName": "${CONNECT_IOT_MONITOR_HOSTNAME}",
 "monitorApplication": "${pwd}/monitor.js",
 "repository": {
        "type": "${CONNECT_IOT_REPOSITORY_TYPE}",
        "settings": {
            "url": "${CONNECT_IOT_REPOSITORY_LOCATION}",
            "path": "${CONNECT_IOT_REPOSITORY_LOCATION}"
        }
    },
    "system": {
        "tenantName": "${TENANT_NAME}",
        "address": "${APPLICATION_PUBLIC_HTTP_ADDRESS}",
        "port": "${APPLICATION_PUBLIC_HTTP_PORT}",
        "timeout": "${APPLICATION_PUBLIC_HTTP_TIMEOUT}",
        "useSsl": "${APPLICATION_PUBLIC_HTTP_TLS_ENABLED}",
        "urlSuffix": "${DISCOVERY_SERVICES_URL_SUFFIX}",
        "isLoadBalancingEnabled": "${DISCOVERY_SERVICES_ENABLED}",
        "authentication": {
            "type": "${APPLICATION_AUTHENTICATION_TYPE}",
            "settings": {
                "domain": "${APPLICATION_AUTHENTICATION_DOMAIN}",
                "username": "${APPLICATION_AUTHENTICATION_USERNAME}",
                "password": "${APPLICATION_AUTHENTICATION_PASSWORD}",

                "clientId": "${SECURITY_PORTAL_CLIENT_ID}",
                "accessToken": "${APPLICATION_ACCESS_TOKEN}",
                "openIdConfiguration": "${SECURITY_PORTAL_PUBLIC_URL}/.well-known/openid-configuration"
            }
        }
    },
    "storage": {
        "type": "Directory",
        "settings": {
            "path": "/usr/iot/persistency",
            "retentionTime": "${CONNECT_IOT_STORAGE_RETENTION_TIME}"
        }
    },
    "logging": [
        {
            "type": "Console",
            "options": {
                "level": "debug",
                "prettyPrint": true,
                "colorizeMessage": true
            },
            "applications": [ "*" ]
        },
        {
            "id": "ControllersAndDrivers",
            "type": "File",
            "options": {
                "filename": "${applicationName}_${date}.log",
                "dirname": "/usr/iot/logs/Instances/${entityNameNormalized}/${componentId}",
                "level": "debug",
                "timestampFormat": "HH:mm:ss.SSSSS",
                "maxSize": "10m",
                "maxFiles": "30d"
            },
            "applications": [ "AutomationController", "Driver*" ]
        },
        {
            "id": "ManagerAndMonitor",
            "type": "File",
            "options": {
                "filename": "${applicationName}_${date}.log",
                "dirname": "/usr/iot/logs/${applicationName}",
                "level": "debug",
                "timestampFormat": "HH:mm:ss.SSSSS",
                "maxSize": "10m",
                "maxFiles": "30d"
            },
            "applications": [ "AutomationMonitor", "AutomationManager" ]
        },
        {
            "id": "Jobs",
            "type": "File",
            "options": {
                "filename": "Job_${jobId}_${date}.log",
                "dirname": "/usr/iot/logs/jobs",
                "auditFile": "/usr/iot/logs/jobs/.audit.json",
                "level": "debug",
                "timestampFormat": "HH:mm:ss.SSSSS",
                "maxSize": "10m",
                "maxFiles": "30d"
            },
            "applications": [
                "AutomationJob"
            ]
        }
    ]
}

示例#

以下示例解释了在某些特殊情况下应执行的操作。提供的命令行仅用作示例。必须对它们进行调整以与您的操作系统、目录位置、版本等相匹配

使用共享目录作为目录代码库#

假定目录位于\\10.24.14.17\public\jpsantos\Repository中并且受用户名/密码保护。

docker volume create --driver local --opt type=cifs --opt device=//10.24.14.17/public/jpsantos/Repository --opt o=user=cmfsu,domain=cmf.criticalmanufacturing.com,password="ThIsMyPaSsWoRd" repositoryVolume

docker run -it --env-file C:\docker\envVariables.txt --name iot --volume repositoryVolume:/usr/iot/repository criticalmanufacturing.io/criticalmanufacturing/connectiot:8.0.0

envVariables.txt文件的主要条目:

CONNECT_IOT_REPOSITORY_TYPE=Directory
CONNECT_IOT_REPOSITORY_LOCATION=/usr/iot/repository

为KeyboardWedge驱动连接USB条形码阅读器#

假定作为/dev/hidraw0挂载的USB阅读器已连接并被系统(在本例中,使用Raspberry Pi Linux Arm,即Raspbian OS)检测到。

为了避免在特权模式下使用Docker映像,首先允许任何用户访问设备。

  1. 列出USB设备
pi@raspberrypi:~/iot $ lsusb
Bus 002 Device 002: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 007: ID ffff:0035
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  1. 确定设备(Bus 001 Device 007: ID ffff:0035)后,创建一个规则文件,以允许任何有权访问系统的用户使用该设备。

    pi@raspberrypi:~/iot $ sudo nano /etc/udev/rules.d/rfid.rules
    SUBSYSTEM=="usb", ATTRS{idVendor}=="ffff", ATTRS{idProduct}=="0035", MODE="0777"
    
  2. 重启系统以应用规则

最后一步是启动容器并转发对设备的访问

docker run -it --device /dev/hidraw0:/dev/hidraw0 --env-file /home/pi/iot/env.txt --name iot criticalmanufacturing.io/criticalmanufacturing/connectiot:8.0.0

Note:在工作流Equipment Setup任务中,您必须将设备的位置设置为映像中定义的设备映射位置。在本例中,设备保持为 /dev/hidraw0

连接串行设备#

某些自动化操作需要访问串行设备。与上一个示例一样,必须允许从容器访问物理设备,但对于串行设备,则不必提供特殊的访问规则。

docker run -it --device /dev/serial0:/dev/serial0 --env-file /home/pi/iot/env.txt --name iot criticalmanufacturing.io/criticalmanufacturing/connectiot:8.0.0

使用通过文件驱动进行访问的已挂载位置#

假定位置/home/pi/iot/device指向一个外部位置,设备将在该外部位置放置要由物联网模块处理的文件。

docker run -it --volume /home/pi/iot/device:/usr/iot/toolDirectory --env-file /home/pi/iot/env.txt --name iot criticalmanufacturing.io/criticalmanufacturing/connectiot:8.0.0

Note:在工作流Equipment Setup任务中,您必须按照映像中的定义设置设备的映射位置。在本例中,设备设置为 /usr/iot/toolDirectory

使用Raspberry Pi随附的蓝牙设备#

Note:该设备还不能完全工作,但已能够扫描现有设备。连接时有时会出错,需要重试几次。在找到解决方案之前,建议不要在容器内使用BLE驱动。

docker run -it --cap-add=SYS_ADMIN --cap-add=NET_ADMIN --net=host --env-file /home/pi/iot/env.txt --name iot --device /dev/ttyAMA0 criticalmanufacturing.io/criticalmanufacturing/connectiot:8.0.0

在Raspberry Pi中安装Docker#

已根据https://phoenixnap.com/kb/docker-on-raspberry-pi ⧉中的教程对以下指令进行测试。

sudo apt-get update && sudo apt-get upgrade
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# optional, add user pi into docker group to allow running docker commands without sudo
sudo usermod -aG docker pi

docker version