簡體   English   中英

從 Windows docker 容器內向 Azure IoT Hub 發送消息

[英]Sending messages to Azure IoT Hub from within Windows docker container

I am pretty new to Docker and I have to build a container that can run a Python script that sends messages periodically to an Azure IoT Hub using the rows of a CSV file. 我已經使用 Linux 構建了這個容器,但是由於我的資源限制,我必須使用 Windows 容器重建圖像。 這是我嘗試使用的 Dockerfile 的設置:

FROM mcr.microsoft.com/windows/servercore:1809

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app 
ADD SimulatedDeviceFitbit.py .

WORKDIR /app 
COPY sensor_original2.csv .

CMD ["python", "SimulatedDeviceFitbit.py"]

使用 Pip 添加的唯一 package 是 azure-iot-device 庫。 CSV 用於讀取將作為消息發送的數據,腳本處理消息的發送。 每當我運行圖像時,錯誤:

azure.iot.device.common.transport_exceptions.TlsExchangeAuthError: TlsExchangeAuthError(None) caused by SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')

腳本中與 IoT 中心的連接如下所示:

client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)

我通過 Docker 檢查了我的網絡設備,沒有發現任何問題,但顯然我遺漏了一些東西。 我沒有在容器中聯網的經驗,希望得到任何指導。

我相信您的容器映像缺少巴爾的摩根 CA。

當您使用Windows 服務器核心容器映像時,您可能需要啟用一些 WindowsFeatures 才能使用certutil將證書導入證書存儲。

您的 DockerFile 應包括以下內容:

# Copy PFX file (located on HOST on C:\test) to container and install
ADD "c:\test\BaltimoreRootCA.pfx" "c:\test\BaltimoreRootCA.pfx"
RUN certutil -importpfx "c:\test\BaltimoreRootCA.pfx"

You can export Baltimore Root CA from a windows machine or copy it from Azure IoT SDK C Github Repo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM