Container Logging u0026 Monitoring with Docker Quiz Quiz

This quiz explores key principles of container logging and monitoring within Docker environments, focusing on best practices, log management methods, and monitoring container health. Designed to assess and expand your understanding of efficient container observability, the quiz covers logging drivers, centralized log collection, and crucial monitoring metrics.

  1. Understanding Log Drivers

    Which log driver should you select when you want to send container logs directly to the host's syslog service for centralized log collection?

    1. json-file
    2. xmlfile
    3. syslog
    4. journald

    Explanation: The 'syslog' log driver routes container logs to the host’s syslog service, enabling centralized log management. 'json-file' stores logs locally in JSON format on the host, which is not designed for integration with centralized logging. 'journald' places logs into the journal system rather than syslog, and 'xmlfile' does not exist as a standard log driver and is likely a typographical error.

  2. Accessing Container Logs

    If a running container is using the default log driver, which command displays its standard output and error streams, including recent messages?

    1. docker inspect u003Ccontainer_idu003E
    2. cat /var/log/messages
    3. docker events
    4. docker logs u003Ccontainer_idu003E

    Explanation: Using 'docker logs u003Ccontainer_idu003E' accesses the stdout and stderr streams of a running or stopped container with the default log driver. 'cat /var/log/messages' reads general system logs and doesn't target container logs specifically. 'docker inspect' provides details about the container's settings but not live logs. 'docker events' tracks real-time events, not log output.

  3. Centralized Log Management

    In a multi-container setup, which logging strategy improves efficiency and simplifies troubleshooting by aggregating all container logs in one location?

    1. Centralized logging
    2. Inline logging
    3. Verbose logging
    4. Log rotation

    Explanation: Centralized logging brings together logs from all containers, making it easier to search and analyze events across the infrastructure. Log rotation prevents disk overuse but does not aggregate logs. Verbose logging increases detail but may cause noise and doesn't aggregate logs. Inline logging is not a standard term for log management in this context.

  4. Monitoring Container Health

    Which metric is most useful for monitoring the health and resource usage of a running container in a production environment?

    1. Hostname
    2. User ID
    3. CPU usage
    4. Root directory size

    Explanation: CPU usage is a key resource metric that reflects the performance and load of a running container, helping identify potential bottlenecks. Root directory size is less commonly monitored in this context and isn't a standard health metric. Hostname and user ID provide identification but do not indicate health or resource utilization.

  5. Dealing with Increasing Log Volume

    When log files on a host start to consume excessive disk space due to high logging activity from multiple containers, what practice helps manage disk usage effectively?

    1. Disabling error logging
    2. Reducing container port mapping
    3. Enabling log rotation
    4. Increasing container image size

    Explanation: Log rotation manages disk usage by archiving old logs and limiting log file sizes, preventing uncontrolled disk consumption. Disabling error logging may result in missing critical debugging information. Increasing container image size does not affect log storage. Reducing container port mapping is unrelated to log management and disk usage.