Monitoring the health and status of Docker containers is crucial for maintaining a reliable and efficient environment. Monocker is a lightweight tool designed to address this need by monitoring Docker container state changes and sending real-time alerts through various messaging platforms.
What is Monocker?
Monocker, short for “MONitors dOCKER,” is an open-source application that keeps track of Docker container states and notifies users of any changes. Whether a container transitions to paused, exited, unhealthy, or dead states, Monocker ensures you’re promptly informed, enabling swift action to maintain system stability.
Key Features
- Comprehensive Monitoring: Tracks state changes across all Docker containers, ensuring no event goes unnoticed.
- Customizable Alerts: Supports multiple messaging platforms, including Telegram, Pushbullet, Pushover, Discord, Ntfy, Slack, Gotify, Matrix, and Apprise, allowing users to choose their preferred notification method.
- Selective Monitoring: Offers options to include or exclude specific containers from monitoring, and to alert only on particular state changes, reducing unnecessary notifications.
- Health Checks: Incorporates built-in Docker health checks to provide insights into container health status.
Getting Started with Monocker
Deploying Monocker is straightforward, especially with Docker Compose. Here’s a sample configuration:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
version: '2.4' services: monocker: container_name: monocker image: petersem/monocker environment: SERVER_LABEL: 'YourServerName' # Optional label to identify the server MESSAGE_PLATFORM: 'telegram@your_bot_id@your_chat_id' # Replace with your details # Other platforms: # MESSAGE_PLATFORM: 'pushbullet@your_api_key@your_device_id' # MESSAGE_PLATFORM: 'pushover@your_user_key@your_app_api_token' # MESSAGE_PLATFORM: 'discord@webhook_url' LABEL_ENABLE: 'false' # Set to 'true' to monitor specific containers ONLY_OFFLINE_STATES: 'false' # Set to 'true' to alert only on offline states EXCLUDE_EXITED: 'false' # Set to 'true' to ignore 'exited' state changes PERIOD: 10 # Polling period in seconds DISABLE_STARTUP_MSG: 'false' # Set to 'true' to suppress startup messages volumes: - /var/run/docker.sock:/var/run/docker.sock:ro restart: unless-stopped |
This configuration connects Monocker to the Docker socket, enabling it to monitor container states. Ensure you replace the MESSAGE_PLATFORM variable with your specific credentials. For detailed setup instructions and additional configuration options, refer to the Monocker GitHub repository.
Environment Options
Item | Required | Description |
|---|---|---|
DOCKER_HOST | False | Use a docker interface other than the default. (E.G DOCKER_HOST: tcp://docker-socket-proxy:2375) |
- This can be a UNIX socket (
unix://), Windows named pipe (npipe://) or TCP connection (tcp://). If it’s a pipe or socket, be sure to mount the connection as a volume. If the connection is proxied, ensure thatGETrequests are allowed on the/containersendpoint.- By default, this value is unset and the connection will use
/var/run/docker.sock.
Item | Required | Description |
|---|---|---|
SERVER_LABEL | False | Label to preface messages. Handy if you are running multiple versions of Monocker. |
SERVER_AVATAR | False | Avatar image URL to add to messages. Handy if you are running Monocker on different machines (discord, ntfy mobile, and slack) |
ONLY_OFFLINE_STATES | False | When true, only notify when a container state changes to paused, exited, running (unhealthy), or dead. Otherwise, all state changes are notified (false) |
EXCLUDE_EXITED | False | Regardless of any other settings, you can ignore or include the status of ‘exited’. ( false includes exited) |
PERIOD | False | Set the poll period in seconds. Default/Minimum is 10 seconds, recommended 30 seconds, to minimise messages sent. |
DISABLE_STARTUP_MSG | False | Suppresses startup messages from being sent. Default is false |
SHA | False | Will include the container SHA ID in sent messages |
MESSAGE_PLATFORM | True | Specify ‘ONE’ messaging platform. |
- ‘pushbullet@your_api_key@your_device_id’
- ‘pushover@your_user_key@your_app_api_token’
- ‘discord@webhook_url’
- ‘ntfy@topic_title’
- ‘slack@bot_user_oauth_token@your_chat_id’
- ‘gotify@server_url@app_token’
- ‘telegram@your_bot_id@your_chat_id’
- ‘apprise@apprise_url@config_id@tag’ (Only one tag is supported, and server_avatar is not currently supported)
- ‘matrix@https://matrix.org@user:matrix.org@access-token@room-id:matrix.org‘ (For Matrix, add the userid ‘without’ the leading @ sign. Values are server, userid, access-token, room-id)
Advanced NTFY Setting (I love ntfy)
Use these settings if you host your own Ntfy server, or otherwise require authentication to connect.
Item Required Description CUSTOM_NTFY_SERVER False The URL for your self-hosted Ntfy server (Else will use https://nttp.sh) NTFY_USER False The username to login (on ntfy.sh or your own server. Optional if you have your own server open) NTFY_PASS False The password to login (on ntfy.sh or your own server)
Item | Required | Description |
|---|---|---|
LABEL_ENABLE | False | Includes or excludes specified containers, if labelled. (defaults to false) |
This feature allows you to specify (with labels in your yaml) ‘either’ to monitor or exclude specific containers.
- If it is set to
false, then all containers will be monitored, except for any containers with the following label:labels: monocker.enable: 'false'
- If it is set to true,
onlycontainers with the following label will be monitoredlabels: monocker.enable: 'true'
- If you just want to monitor everything, then set
LABEL_ENABLE: 'false'or just leave it out altogether, and dont worry about labelling any other containers.
Why Use Monocker?
In environments where uptime and reliability are paramount, being aware of container state changes is essential. Monocker provides a simple yet effective solution to stay informed about your Docker containers’ statuses, allowing for proactive management and quick resolution of potential issues.
By integrating Monocker into your monitoring toolkit, you can enhance your system’s resilience and ensure that critical services remain operational.
