HA-Dockermon – Use Home Assistant to monitor, start or stop Docker Containers

Being a developer, I love the flexibility and power Docker brings to Home Automation. Docker makes it easy to run multiple services which can play a big role in your smart home.

It’s no surprise why HASS.IO, the all-in-one solution is also powered by Docker. Using the power of isolated Docker containers, HASS.IO has the ability to keep Home Assistant up-to-date without the need for the command line. It also powers the concept of Home Assistant Add-ons, which are isolated Docker containers, adding their own additional functionality.

Right now, HASS.IO can only be installed on some Linux based systems. My Synology NAS, which I run Docker from is based on Linux but isn’t compatible with HASS.IO. For the time being, I’m still using Home Assistant via the official Home Assistant DockerHub image. This gives me an always-on network server which is more powerful than a Raspberry Pi and allows me to run multiple applications.

Having such power means I end up running a few Docker containers. These include InfluxDB and Grafana, and MySQL for my history and recorder components. You can also take it further with Docker containers for almost anything else: Transmission Download clients, the Plex media server, ad-blocking software PiHole, and of course even more Home Automation tools like HomeBridge for connecting Home Assistant to your iOS devices.

With so many potential Docker containers, they create more moving parts in your smart home. The more moving parts you have, the more things must be up and operational for your smart home to function. If one of those containers goes down, it would be nice for Home Assistant to be able to bring them back up (or at least notify you if it can’t).


Introducing HA-Dockermon

Home Assistant has great sensor and switch components that can easily be adapted for wide use-cases. Some of those include the RESTful Sensor and RESTful Switch. These components make it easy for Home Assistant to read data from a REST API, and display or utilise them in Home Assistant either as a switch or sensor.

HA-Dockermon is a NodeJS service which can be run from its own Docker container (or NodeJS if you’re that way inclined). It exposes a RESTful API which Home Assistant can call to see the status of Docker containers on your system. As at the first release, here’s what HA-Dockermon can do:

  • Get the status of a container (running, stopped).
  • Start or stop a container by issuing a POST  request.
  • Restart a container by making a GET  request to a URL for the container.


The Latest In Your Inbox

Enter your email address below to receive my latest blog posts and videos about Home Automation in your Inbox


Installing with Docker

The easiest way to get going with HA-Dockermon is to run its own Docker container. The trick is to mount the Docker connection socket using a volume mount. This is critical, as it allows the Docker container to access the host Docker instance, and perform actions against the Docker API directly.

The following run command will spin up a Docker container with HA-Dockermon running on port 8126.

The second volume mount is to mount a config directory. You can use this to add a configuration.yaml file to define additional settings like a username and password which must be used to call the service. This mount is optional, and default settings will be used if you don’t set it. See the GitHub repo for the default settings and an example file.


Adding to Home Assistant

Because HA-Dockermon is designed to work with RESTful Switches and Sensors, adding these to Home Assistant just requires a few lines of YAML in your configuration file.

Once you’ve added those switches, you can use customise to add some icons, and then use groups to add them to your Home Assistant front-end.

Here’s how that card now looks in Home Assistant

Tapping those switches on or off will send their respective docker start  and docker stop  commands to the containers.


Restarting Home Assistant

One problem I have running Home Assistant in a Docker container is that the stop and restart Home Assistant buttons don’t work. For some reason, Home Assistant is unable to stop the container, and the container just hangs with Home Assistant down and unusable. This means each time I make a change to my config that needs a Home Assistant restart, I need to SSH into my Synology NAS to execute docker restart home-assistant .

HA-Dockermon includes a /restart  endpoint which can be added after the container name in the URL. This allows you to simply make a call to a URL to restart a container, like Home Assistant.

Here’s a shell command and script you can add to your Home Assistant which will make a call to HA-Dockermon to restart Home Assistant.

We can then add that to a Home Assistant group, and we’ll see a nice Activate button which will restart the entire Home Assistant Docker container.


Adding Alerts

Now that we have those switches inside Home Assistant, we can use them like any other normal switch. For example, we might want to send an alert if the MySQL or MQTT containers crashed and haven’t been up for 5 minutes.


Automating When Containers Run/Stop

Another thing we can now do is automate when Docker containers are run or stopped. Here’s an example automation that would shut down a Plex Media Server container when the Harmony Remote turns off the TV after midnight, or at midnight if the TV is already turned off.



Other Ideas

So far, this has been a great addition to my Home Assistant setup. I now have more visibility into the moving parts of my smart home from within Home Assistant. There’s an extra layer of security knowing that Home Assistant has the ability to inform me that something isn’t right before I or someone else in the house notice.

My use case was pretty basic. To give me the ability to send alerts when something is wrong, and to restart Home Assistant remotely. Of course, you could use this to go a few steps further (and I hope you do). Here are some ideas you could explore with HA-Dockermon.

  • Combine with the Certificate Expiry sensor to have Certbot automatically regenerate an SSL certificate, and then reboot the Home Assistant container when it’s done. This will ensure your Home Assistant always has a valid SSL certificate, and you don’t need to do anything.
  • Voice control Docker containers. Ask Alexa to restart Home Assistant instead of finding the reset button in the UI. Or tell Google Assistant to turn off Transmission because you’re trying to stream Netflix.
  • Detect when your host machine is using too many resources (RAM, CPU etc) and shut down any non-critical Docker containers to improve performance.


Eventually, I’d like to add more features to HA-Dockermon such as pulling/updating images, renaming containers etc. You can star or follow the GitHub repo for the latest updates. If you’ve got another idea on how to use HA-Dockermon, I’d love to hear it too!

Recommended Posts
  • ASA

    That is really quite awesome. And its made me realize how many containers I have running that I use once in a blue moon (calibre, Unifi, …) I can now turn them on as I need them from HA 🙂 Thanks!

  • Jokerigno


    It’s still me!

    I’ve tried to setup this metadocker in my home assistant.

    But it does’nt work.

    This is the log I’ve found:

    Unable to connect to Docker socket at /var/run/docker.sock. Is Docker running?
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] start: node index.js
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    I tried also to run it as root but nothing change.

    Any hint?

    • Looks like your docker socket might be in a different location. Can you post your docker run command?

      • Jokerigno

        This is what I ran:

        docker run -d
        –name=HomeAssistantDockermon –restart=always
        -v /var/run/docker.sock:/var/run/docker.sock
        -p 8126:8126

        I checked into my nas. In var/run folder a docker.sock file exist with root as owner.

  • Love this. Great implementations, please keep them coming.

    I have a somewhat unrelated question that I hope you can help with. I need to access the usr folder of my Home Assistant container image hosted on a Synology NAS at volume1dockerhass-dev. Where is this usr folder normally located and how do I access it with SSH?

    • So just to confirm, you want to access the folder at /volume1/docker/hass-dev? You should be able to use a program like WinSCP to login with your SSH credentials, and then view the contents

      • Hey Phil, nope. I was told to change settings in this file: /usr/local/lib/python3.6/site-packages/pydaikin/appliance.py
        These changes are needed to get my AC unit fixed, but i have no idea where to access this for a container. I SSH’ed into the DSM usr folder, but python3.6 is not even there… Thanks for your trouble

        • Ah right, yes that directory isn’t mounted by default. You can create a new docker container and mount the dir, however I would advise against this.

          When I need to change those files, here’s what I do.

          From the host machine, execute

          Where home-assistant is the name of your running docker container.

          This will give you access to the containers shell. Now, you can

          Now in your Home Assistant config directory in the NAS you’ll see appliance.py. Make your changes to the file and save it. Then, copy back into the /usr folder by doing the reverse to the command above

          Then exit out of the shell, which will bring you back into the SSH of the NAS, then do a docker restart of the container so your new file changes are loaded.

  • By the way Phil,
    My understanding is that Hass-io cannot currently run as a Synology docker container. I’m interested in using a similar implementation to the Let’s Encrypt!/DuckDNS plug-in for Hass-io. This is needed to use things like Google Assistant that require SSL external access. Have you toyed with this at all?

    • Yeah that’s right. HASS.IO currently isn’t compatible with Synology.

      I have looked into the DuckDNS side of things. I’m surprised Home Assistant doesn’t have a component to do that to be honest.

      I currently don’t use SSL, but might be a good idea for another post once I get it working. There’s a docker image you can use which will generate, or renew a SSL certificate from Let’s Encrypt (called Certbot). I didn’t get very far into automating it though.

      You would essentially create a scheduled task in Synology, to renew the certificates with the certbot container, then restart the Home Assistant container so that it loads the new certificates

      • Ced

        Cheers for that Phil. I’ll give it a try!

  • Ced

    Mmh, I’m having no luck running this one. Here is the code I used (adapted to DSM 6.1):
    ”’docker run -d


    —-mount type=bind,source=/run/docker.sock,target=/run/docker.sock

    -—mount type=bind,source=/volume1/docker/dockermon/config,target=/config

    -p 8126:8126

    The error message I get is
    docker: invalid reference format.
    See ‘docker run –help’.

    Still no luck using -v either…
    Running out of ideas!

    • So strange.

      I’m not sure if it is a copy/paste issue, but I noticed there are two types of dashes in front of the mount there. There’s a long dash and a small dash. Not sure if that might be causing the issues?

      • Ced

        Oh, yeah! I see what you mean… I shall give it another try as soon as I get home. I really see a lot of value to this and hope to make it work!

Start typing and press Enter to search