Monocker - A Docker State Change Monitor and Notifier

Get notified via push when your Docker containers change state. 🐳

Monocker - A Docker State Change Monitor and Notifier

One of the most undervalued tools in my Docker toolbox is one that alerts you whenever your Docker container changes states. For example, if your container all of the sudden gets sick and changes to the "unhealthy" state, you can be alerted of this so you can check your logs and diagnose the issue before things get worse.

What is Monocker?

Monocker monitors Docker (MONitors dOCKER) containers and alerts on 'state' change.

Monocker is nothing more than an alert tool for Docker containers but this simple tool can help you stay ahead of the game if an issue arises. This could be especially useful in a production environment if you host critical containers that require supervision when you can't be there 24/7.

Install Monocker using Docker Compose

Use the following Docker Compose stack to install Monocker on your Docker host.

version: '2.4'

    container_name: monocker
    image: petersem/monocker
      # Optional label to preface messages. Handy if you are running multiple versions of Monocker
      SERVER_LABEL: 'Dev'
      # Specify the messaging platform and details, or leave blank if only wanting container logs (pick one only)
      MESSAGE_PLATFORM: 'telegram@your_bot_id@your_chat_id'
      # MESSAGE_PLATFORM: 'pushbullet@your_api_key@your_device_id'
      # MESSAGE_PLATFORM: 'pushover@your_user_key@your_app_api_token'
      # MESSAGE_PLATFORM: 'discord@webhook_url'
      # Optional - includes or excludes specified containers - default behaviour is false
      LABEL_ENABLE: 'false'
      # Optional - only show when container state changes to being offline (paused, exited, running (unhealthy), or dead) - default is false
      ONLY_OFFLINE_STATES: 'false'
      # [Optional] - Regardless of any other settings, you can ignore or include 'exited'
      EXCLUDE_EXITED: 'false'      
      # [Optional] - Set the poll period in seconds. Defaults to 10 seconds, which is also the minimum. 
      PERIOD: 10
      # [Optional] - Supress startup messages from being sent. Default is false
      DISABLE_STARTUP_MSG: 'false'
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

This will connect Monocker to the docker.sock so it can read the state of your containers. There is no web ui or fancy dashboard, simply uncomment the message platform you choose to use with the correct API information and start receiving alerts from your Docker host.

If you choose to run Monocker on more than one Docker host, it's a good idea to use the environment variable SERVER_LABEL so you know which server is sending the alert.

You can further granulate the messages that are sent via environment variables right down to specific containers.

I chose to use Pushover for alerts. Setup was pretty simple and it works well as you can see in the image below.

It shows my server name in parentheses followed by the container and the current state.

Final Notes and Thoughts

I have been using Monocker for just about 2 years. Shortly after I heard about it I gave it a try and was really impressed. Monocker has helped me keep containers running smoothly across the board.

If you run Watchtower, I highly suggest running Monocker along side just in-case your Watchtower breaks something when automatically updating your containers. This way you can be alerted right away instead of finding out your app went down from a friend or family member... or a boss or coworker.

If you find Monocker useful, be sure to swing by the Monocker Github repo and give it a star!