Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/knutkirkhorn/docker-container-status-notifier
🐳⏰ Notifier for Docker container statuses
https://github.com/knutkirkhorn/docker-container-status-notifier
docker docker-container docker-image nodejs notification notifier status
Last synced: about 1 month ago
JSON representation
🐳⏰ Notifier for Docker container statuses
- Host: GitHub
- URL: https://github.com/knutkirkhorn/docker-container-status-notifier
- Owner: knutkirkhorn
- License: mit
- Created: 2020-02-25T20:13:16.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T23:06:02.000Z (over 1 year ago)
- Last Synced: 2024-04-23T23:05:14.809Z (9 months ago)
- Topics: docker, docker-container, docker-image, nodejs, notification, notifier, status
- Language: JavaScript
- Size: 262 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docker-container-status-notifier
> 🐳⏰ Notifier for Docker container statuses
[![Docker Pulls](https://img.shields.io/docker/pulls/knutkirkhorn/docker-container-status-notifier)](https://hub.docker.com/r/knutkirkhorn/docker-container-status-notifier) [![Docker Image Size](https://badgen.net/docker/size/knutkirkhorn/docker-container-status-notifier)](https://hub.docker.com/r/knutkirkhorn/docker-container-status-notifier)
Notify for changes in Docker container statuses. Notify to a Discord channel using [Discord Webhooks](https://discordapp.com/developers/docs/resources/webhook).
## Usage
### Within a Docker container
It is possible to run this code inside a Docker container by passing the volume (`-v`) flag with the `run` command. This will pass the Docker daemon socket from the host to the container and enable calls to the [Docker Engine API](https://docs.docker.com/engine/api/latest). In this code the API is called using the [dockerode](https://github.com/apocas/dockerode) module by checking for updates in the stream to the [Events API](https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents).
#### From Docker Hub Image
This will pull the image from [Docker Hub](https://hub.docker.com/) and run the image with the provided configuration for web hooks as below. One can provide only the Webhook URL or both the Webhook ID and token.
```sh
# Providing Discord Webhook URL
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-e DISCORD_WEBHOOK_URL= \
knutkirkhorn/docker-container-status-notifier# Providing both Discord Webhook ID and token
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-e DISCORD_WEBHOOK_ID= \
-e DISCORD_WEBHOOK_TOKEN= \
knutkirkhorn/docker-container-status-notifier
```#### From source code
```sh
# Build container from source
docker build -t docker-container-status-notifier .# Run the built container
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-e DISCORD_WEBHOOK_URL= \
docker-container-status-notifier
```### Outside of a Docker container
```sh
# Install
npm install# Run
npm start
```### Environment variables
Provide these with the docker run command or store these in a `.env` file. Only `DISCORD_WEBHOOK_URL` or both `DISCORD_WEBHOOK_ID` and `DISCORD_WEBHOOK_TOKEN` are required.
- `DISCORD_WEBHOOK_URL`
- URL to the Discord Webhook containing both the ID and the token
- Format: `DISCORD_WEBHOOK_URL=https://discordapp.com/api/webhooks//`
- `DISCORD_WEBHOOK_ID`
- ID for the Discord Webhook
- `DISCORD_WEBHOOK_TOKEN`
- Token for the Discord Webhook## Screenshots
![Container created](https://raw.githubusercontent.com/knutkirkhorn/docker-container-status-notifier/main/media/container-created.png)
![Container started](https://raw.githubusercontent.com/knutkirkhorn/docker-container-status-notifier/main/media/container-started.png)
![Container stopped](https://raw.githubusercontent.com/knutkirkhorn/docker-container-status-notifier/main/media/container-stopped.png)
![Container killed](https://raw.githubusercontent.com/knutkirkhorn/docker-container-status-notifier/main/media/container-killed.png)
![Container removed](https://raw.githubusercontent.com/knutkirkhorn/docker-container-status-notifier/main/media/container-removed.png)