source ../environment.sh
if [ -z "$NETWORK" ]; then
echo "错误: 未找到 NETWORK 环境变量"
exit 1
fi
if [ -z "$MQTT_PORT" ]; then
echo "错误: 未找到 MQTT_PORT 环境变量"
exit 1
fi
if [ -z "$MQTT_WS_PORT" ]; then
echo "错误: 未找到 MQTT_WS_PORT 环境变量"
exit 1
fi

if docker ps -a | grep -q ${MQTT_NAME}; then
    echo "停止并删除已存在的 MQTT 容器..."
    docker stop ${MQTT_NAME} >/dev/null 2>&1
    docker rm ${MQTT_NAME} >/dev/null 2>&1
fi


docker run -d \
--name ${MQTT_NAME} \
--network $NETWORK \
-p ${MQTT_PORT}:1883 \
-p ${MQTT_WS_PORT}:9001 \
--memory ${MQTT_MEMORY} \
--restart unless-stopped \
-v $(pwd)/volumes/mqtt/mosquitto.conf:/mosquitto/config/mosquitto.conf \
${MQTT_IMAGE}

docker ps