Coder Social home page Coder Social logo

david-lor / mqtt2docker Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 8 KB

Shell scripts to interact with Docker containers through MQTT

License: Apache License 2.0

Shell 100.00%
mqtt docker container container-management containers mqtt-client mqtt-bridge mqtt-protocol docker-container docker-socket

mqtt2docker's Introduction

MQTT2Docker

Bash scripts to perform simple Docker container management through MQTT, and send container events to MQTT.

Scripts

  • mqtt2docker subscribes to MQTT and performs simple operations (like Start, Stop) on containers
  • docker2mqtt subscribes to Docker events API and publishes them on MQTT

mqtt2docker

Publish messages to mqtt/<containerName>/cmd to send commands to a container.

Example: START a container named portainer: send a message to the topic mqtt/portainer/cmd with the payload start (payload is not case-sensitive)

Commands (payloads) available

  • START
  • STOP
  • RESTART
  • PAUSE
  • UNPAUSE
  • KILL

docker2mqtt

The script will publish all events occurring on a container to mqtt/<containerName>/stat.

Example: when a container named portainer starts: a message to the topic mqtt/portainer/stat is published with the payload start.

Env variables

Use environment variables as configurations:

  • MQTT_HOST: host where the MQTT broker is running (if not specified: localhost)
  • MQTT_UID: UID of the user that will run the mosquitto_sub/mosquitto_pub commands (if not specified: 1000)
sudo bash MQTT_HOST=127.0.0.1 MQTT_UID=1000 mqtt2docker.sh

Premises

  • Scripts read or write on the Docker API socket (/var/run/docker.sock), so they must run as root
  • Scripts are written in pure Bash, but require mosquitto-client (MQTT client) and jq (JSON parser) packages
  • Calls to mosquitto_pub and mosquitto_sub are performed by another user different than root
  • Both scripts can run on Docker containers mapping the /var/run/docker.sock as a bind volume

TODO

  • Create Docker images
  • (More) Setting customization - or pass arguments to the script to be part of the mosquitto_sub/mosquitto_pub args
  • Add binary pub/sub endpoints (ON/OFF - like payloads)

Changelog

  • 0.1 - Initial release

mqtt2docker's People

Contributors

david-lor avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.