DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Understanding and Using Docker Containers in Web Development: A Guide
  • Ways To Reduce JVM Docker Image Size
  • Comparative Analysis of Open Source Cluster Management Systems: Kubernetes vs. Apache Mesos
  • Simplify Docker Container Management at Scale With Amazon ECS

Trending

  • Java Collection Overhead
  • Apply Strangler Pattern To Decompose Legacy System Into Microservices: Part 1
  • Introducing the Apache JMeter Docker Extension
  • A Roadmap to True Observability
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Get Alerts When Docker Containers Run Into Issues

Get Alerts When Docker Containers Run Into Issues

Learn how to get alerts when your Docker containers stop running or are unhealthy by querying the status via the Docker Unix socket file.

Denny Zhang user avatar by
Denny Zhang
·
Updated Aug. 31, 17 · Tutorial
Like (3)
Save
Tweet
Share
16.8K Views

Join the DZone community and get the full member experience.

Join For Free

I'm running Docker containers for all my side projects, usually one single container, sometimes multiple containers started by docker-compose[1].

If containers get issues, I want to get alerts.

What a typical monitoring requirement! But if you do some research, you will find the information is just overwhelming. cAdvisor, Prometheus, InfluxDB, etc. Excuse me? Can't we have a simple solution for this simple requirement? Here is my answer. Try it and discuss with me.

This solution works for docker-compose deployments. Please check Prometheus[2] for more complex Docker environments.

Basic Idea

First, I admit: Prometheus can do the job. Yes, it's capable, but ...

Hint: If you want to use Prometheus in a relatively easy way, try dockprom[3].

Frankly speaking, learning Prometheus took much longer than what I had expected. And it's a bit over-killing for my scenario. A Prometheus solution itself will start multiple containers. But my envs only have very few containers to monitor.

Ironically "docker ps -a" can easily answer most of my questions.

root@denny-blog:~# docker ps -a
CONTAINER ID    IMAGE             COMMAND                  CREATED         STATUS                     PORTS                   NAMES
2936e1d7ec34    denny_wordpress   "/bin/sh -c /docke..."   3 weeks ago     Up 13 days (healthy)       0.0.0.0:443->443/tcp    blog-wordpress
87665b7a76df    mysql:5.7         "docker-entrypoint..."   3 weeks ago     Up 3 weeks                 3306/tcp                blog-mysql
4aa821fa9d37    denny/ss:v2       "ssserver -c /etc/..."   3 weeks ago     Up 3 weeks (healthy)       0.0.0.0:6187->6187/tcp  shadowsock
ea96f4dbefaa    ubuntu:14.04      "/bin/bash"              14 seconds ago  Exited (0) 6 seconds ago                           nginx-test
  1. To get stopped containers: just check the "STATUS" of each container.
  2. To get unhealthy containers: check the status for "unhealthy" output.

    Hint: To enable Docker healthcheck, you need to update your Dockerfiles properly.
  3. Send alerts whenever any of above occurrences have happened. Should be easy, right?

So how about we start a container, which keeps polling status of all containers, then send out alerts if necessary?

You may think: we won't be able to run "docker ps" in containers. It only runs in Docker host.

Yes, you're right. But there is one way out. You can query the status via the Docker Unix socket file. Try it below locally; you will understand.


docker run -v /var/run/docker.sock:/var/run/docker.sock \
    -t -d --privileged --name test-socket \
    --entrypoint=/bin/sh byrnedo/alpine-curl

docker exec -it test-socket \
    curl -XGET --unix-socket /var/run/docker.sock \
    http://localhost/containers/json

How to Use

Check the code in GitHub.

Try it if you find it's useful, and discuss it with me.

Docker (software)

Published at DZone with permission of Denny Zhang, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Understanding and Using Docker Containers in Web Development: A Guide
  • Ways To Reduce JVM Docker Image Size
  • Comparative Analysis of Open Source Cluster Management Systems: Kubernetes vs. Apache Mesos
  • Simplify Docker Container Management at Scale With Amazon ECS

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: