Docker2mqtt: monitor docker containers over mqtt

My quest to turn HA into a dashboard for all my home network monitoring needs continues. :slight_smile: Today I’ve released my program that monitors docker containers on a host and publishes their status to MQTT:

It’s small, lightweight, and exposes all of the events. This means that even brief restarts are captured in HA’s state table.

6 Likes

Thats awesome… does your program support MQTT authentication? The example does not appear to show any

It didn’t, but someone contributed that to ping2mqtt. I copied it over to docker2mqtt and a new release should hit docker hub within 20 or 30 minutes of this message.

2 Likes

Cool… will give it a try straight away! thnx!

Thanks for this, will give it a try.

I have more than one docker host and rather than running a Docker2mqtt instance on each host it would be great if you could connect via LAN to other docker hosts. Don’t you have plans for this capability?

I don’t have plans to add support for connecting to remote docker hosts, but I’d accept a PR for that feature. That said, I would recommend just running a copy of this on each docker host. If you do that when a host goes down all its containers will be marked down in Home Assistant at once thanks to the docker/<host>/status topic changing to offline.

when trying to run this container on a Pi based docker setup i get "exec user process caused “exec format error” after downloading and extracting the images. Could it be this image has not been build for the Pi architecture?

You are correct, I have not had a chance to setup automated builds for other architectures yet. You can clone the git repo and use docker build -t docker2mqtt . to build a container yourself. I will get this setup at some point but it’s not a trivial process. :confused:

I really like the auto discovery of container sensors. I’m using ha-dockermon primally for the ability to restart a container that likes to bug out, but setting up the sensors is a bit of a pain. I’m asking this without any idea what the implications of such a request are, but any plans on giving your container more control over the docker environment? Like enabling the starting and stopping of other containers?

I don’t have plans for that right now, but it’s an interesting use to ponder.

This is a great container. It is very responsive, and I currently use it to monitor my container. Would be great though if information on potential updates could be integrated, something like What's up Docker?

Both projects combined would be the ultimate monitoring tool. Polling for image updates every hour or so and at the same time getting near instant status updates on the containers.

Just a quick question though: the topic contains my_docker_host, where is this coming from?

Glad you find it useful!

Adding some docker monitoring is an interesting idea. I’ve never actually had docker itself crash though, so I didn’t think to do it. Maybe I’ll look at that today.

That comes from the DOCKER2MQTT_HOSTNAME variable, which you’ve set (probably by copying the docker-compose from the README.) If that is not set it will pick up the container’s hostname, so you probably want to set it to your docker host’s hostname.

The monitoring I referred to is not so much for Docker, but a check on the availability of updates for the base images of the containers. My main issue right now is I need a check to see if an update is available for any of the containers, but I don’t want an automatic update. Portainer does not give this info, and I don’t want to use Watchtower as it mostly automatically updates.

Thanks for the info on the source of the topic.

FYI: I’m using this to build a physical desktop clock / Docker Monitor based on an M5Core2 device. The mqtt interface is solving a lot of potential headaches for me!

Ah, I see what you mean. That is an interesting feature, but I would probably want to make it a separate project. I like to follow the unix philosophy- small tools that can easily be combined and chained in unique ways. MQTT is great for that!

That sounds really cool. Are you using ESPHome for the M5Core2, or some other stack?

Totally understandable. I currently use WUD for this, so might as well continue to do that.

I’m using plain Arduino right now. Afaik ESPHome doesn’t support the M5Core2 (yet). Still in the early stages, I currently have an ntp-synced clock and can receive the Docker container statusses over MQTT. Now I just need to put it on the display nicely. :slight_smile:

1 Like

I’m looking to see if docker2mqtt could replace monitor_docker as monitor_docker doesn’t deal well with containers that are recreated (using watchtower or after pulling a new image).

Does d2m create switches to start/stop containers as well, or just sensors for container state?