MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker commands Guide – docker events with examples

Hereโ€™s a complete tutorial on docker events, explaining what it does, a complete list of examples, and use cases.


What is docker events?

docker events is a Docker command that provides a real-time stream of events happening on your Docker daemon. It tracks container lifecycle events (e.g., start, stop, create, kill), network changes, image pulls, and more.

Key Features:

  • Monitors real-time activity on Docker.
  • Helps with debugging, auditing, and automation.
  • Supports filtering by event type, container name, image, and timestamp.

Basic Syntax

docker events [OPTIONS]
Code language: CSS (css)

Common Options:

  • --filter, -f: Filter events by specific criteria (container, image, event type, etc.).
  • --since: Show events starting from a specific time (--since 10m for last 10 minutes).
  • --until: Show events until a specific time (--until 2023-02-07T12:00:00).
  • --format: Format the output using Go templates.

Examples of docker events

1. Show Real-Time Docker Events

docker events

This streams all Docker events in real-time.

Example Output:

2026-02-07T10:30:00.000000000Z container create a1b2c3d4e5f6 (name=my_container, image=nginx:latest)
2026-02-07T10:30:05.000000000Z container start a1b2c3d4e5f6 (name=my_container)
2026-02-07T10:35:00.000000000Z container stop a1b2c3d4e5f6 (name=my_container)

2. Filter Events by Container Name

docker events --filter "container=my_container"
Code language: JavaScript (javascript)

This shows only events related to my_container.


3. Show Events for a Specific Image

docker events --filter "image=nginx"
Code language: JavaScript (javascript)

This displays events triggered by any container running the nginx image.


4. Filter Events by Event Type (start, stop, create, etc.)

docker events --filter "event=start"
Code language: JavaScript (javascript)

This shows only start events for containers.


5. Show Events from the Last 10 Minutes

docker events --since 10m

This displays events that occurred in the last 10 minutes.


6. Show Events Within a Time Range

docker events --since 2023-02-07T10:00:00 --until 2023-02-07T10:30:00
Code language: CSS (css)

This shows events that occurred between 10:00 AM and 10:30 AM on February 7, 2023.


7. Use Custom Formatting for Output

docker events --format '{{json .}}'
Code language: JavaScript (javascript)

This displays events in JSON format for easy parsing.

Example Output:

{"status":"create","id":"a1b2c3d4e5f6","from":"nginx:latest","Type":"container","time":1675773000}
Code language: JSON / JSON with Comments (json)

8. Monitor and Log Events to a File

docker events --since 1h > docker_events.log
Code language: CSS (css)

This saves all events from the last hour to a log file.


9. Watch Network Events

docker events --filter "type=network"
Code language: JavaScript (javascript)

This shows events related to Docker networks (e.g., network creation, connection, and disconnection).


10. Monitor Events for Multiple Filters

docker events --filter "event=start" --filter "event=stop"
Code language: JavaScript (javascript)

This displays only start and stop events for containers.


Use Cases for docker events

1. Real-Time Monitoring

  • Monitor container lifecycle events to ensure services are running properly.
  • Example: Detect when a container stops unexpectedly.

2. Debugging and Troubleshooting

  • Track start, stop, and kill events to debug container issues.
  • Example: Check if a container was killed due to resource limits or manually stopped.

3. Automation and Event-Driven Actions

  • Integrate docker events with automation tools to trigger actions based on events.
  • Example: Automatically restart a container when it stops.

4. Auditing and Security Monitoring

  • Audit Docker activity to detect unauthorized image pulls, container creations, or deletions.
  • Example: Monitor network changes to detect unexpected behavior.

5. Resource Management and Scaling

  • Track CPU and memory usage spikes using external tools combined with docker events.
  • Example: Trigger scaling actions based on high CPU usage.

6. Logging and Analytics

  • Combine with centralized logging tools to build custom dashboards and reports.

List of Common docker events Commands

CommandDescription
docker eventsShow real-time Docker events
docker events --filter "container=my_container"Filter events for a specific container
docker events --filter "image=nginx"Show events for containers using the nginx image
docker events --filter "event=start"Show only container start events
docker events --since 10mShow events from the last 10 minutes
docker events --since 2026-02-07T10:00:00 --until 2026-02-07T10:30:00Show events in a specific time range
docker events --filter "type=network"Monitor network-related events
docker events --format '{{json .}}'Show events in JSON format

Best Practices for Using docker events:

  1. Use filtering (--filter) to avoid overwhelming output and focus on relevant events.
  2. Combine with external monitoring tools (e.g., Prometheus, Grafana) for advanced alerting and dashboards.
  3. Log events to a file for future reference or audits.
  4. Automate recovery actions based on container events (e.g., restart a failed container).
  5. Monitor network events to detect security incidents or misconfigurations.

Common Errors and Solutions

  1. No output from docker events
    โ†’ Ensure that Docker is running. Use docker ps to verify.
  2. Too many events
    โ†’ Use --filter and --since to reduce the output and focus on specific events.
  3. Event data is hard to parse
    โ†’ Use --format '{{json .}}' for structured JSON output.

Combining docker events with Other Tools

1. Automate Recovery with a Shell Script

docker events --filter "event=die" | while read event; do
  docker start $(echo $event | grep -o -E '[a-z0-9]{12}')
done
Code language: PHP (php)

Automatically restart any container that stops.

2. Monitor Events and Send Alerts

Integrate with tools like Prometheus, Grafana, or Slack to receive real-time alerts based on events.


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Debug for Docker Container

To debug a Docker container, check its state and logs first, then its network configuration, then test connectivity from another container on the same network. This page…

Read More

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

Learn how to run Jenkins in Docker with correct port mapping, persistent storage, and operational commands. This updated guide keeps the original workflow but adds modern, production-minded practices.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Install Atlassian Jira with Docker: Quick Start, Persistent Volumes, and Deployment Checks

This guide shows how to run Jira in Docker using the original one-line command, then improve it with persistent storage and repeatable deployment steps. It also includes a workflow diagram, command examples, and practical validation checks.

Read More

Install Sonatype Nexus with Docker: RM2/RM3 Commands, Validation Steps, and Important Caveats

A structured, production-minded rewrite of the original 2016 Docker setup for Sonatype Nexus Repository Manager 2 and 3. Includes command examples, a workflow diagram, and clear warnings about outdated tags/endpoints.

Read More

Top 5 DevOps Tools To Learn Before Writing Your Dissertation

Writing a technical dissertation is rarely just an exercise in reading sources and formatting chapters. On paper, that sounds like the job. In reality, students in computer…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x