How to run nmcli in balena node-red container

Hi there,

I am trying to execute the following command in node-red: nmcli device disconnect wlan0 using exec:

image

My docker-compose.yml file looks like:

node-red:
    build: ./node-red/node-red
    volumes:
      - 'app-data:/data'
    restart: always
    privileged: true
    network_mode: host
    labels:
      io.balena.features.dbus: '1'
      io.balena.features.firmware: '1'
      io.balena.features.supervisor-api: '1'
    cap_add:
      - SYS_RAWIO
    devices:
      - "/dev/mem:/dev/mem"
      - "/dev/gpiomem:/dev/gpiomem"
      - "/dev/i2c-1:/dev/i2c-1"
      - "/dev/ttyUSB0:/dev/ttyUSB0"
    expose:
      - "80"
    depends_on:
      - google-iot
    environment:
      GOOGLE_CLOUD_PROJECT: 'google-iot-project'
      GOOGLE_IOT_REGION: 'google-iot-region'
      GOOGLE_IOT_REGISTRY: 'google-iot-registry'
      GOOGLE_IOT_SERVICE_ACCOUNT_TOKEN: 'google-iot-service-account-token'
      USERNAME: 'node-red-user'
      PASSWORD: 'node-red-hashed-password'
      PORT: 1234

and Dockerfile of node-red like this:

###
# Build step
###
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:12-stretch-build as build

WORKDIR /

COPY ./node-red-contrib-iot-in-gcp /node-red-contrib-iot-in-gcp

RUN JOBS=MAX npm install -g --production --unsafe-perm \
       node-red \
       node-red-contrib-modbus \
       node-red-contrib-google-iot-core

RUN JOBS=MAX npm install -g /node-red-contrib-iot-in-gcp

###
# Runtime image
###
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:12-stretch-run

RUN apt-get update && apt-get install -yq --no-install-recommends \
  rpi.gpio \
  python-dev \
  python-rpi.gpio \
  libatomic1 \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

# Defines our working directory in container
WORKDIR /usr/src/app

# Copy over the files created in the previous step, including lib/, bin/
COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=build /node-red-contrib-iot-in-gcp /usr/local/lib/node_modules/node-red-contrib-iot-in-gcp

# This will copy all files in our root to the working  directory in the container
COPY ./app ./
COPY ./wait-for-it ./wait-for-it

RUN chmod +x ./wait-for-it/wait-for-it.sh

# server.js will run when container starts up on the device
CMD ["bash", "/usr/src/app/start.sh", "bash", "/usr/src/app/wait-for-it/wait-for-it.sh google-iot:8883 -- echo Google IoT Service is up and running"]

I have red the documentation on this link but could not figure out how to specify the command in node-red exec.

Do I need to specify something beside in the docker-compose file?
Do I need to install something or modify the Dockerfile as well ?
Am I missing something? Looking forward for a solution.

1 Like

If iā€™m not wrong, I think that you only can run this command from HostOS and now you are trying to run this command from the nodeRED service.

Check this documentation to see if then this works ā†’ BalenaOS Masterclass - Balena Documentation

On the other hand, did try to run this the nmcli API? looks old but worth it to give a try ā†’ GitHub - balena-io-modules/nm-api: NetworkManager DBUS API