Skip to content

Debug compose.up

When working with multiple containers, it can be helpful to track their statuses in real time. The compose.up function provides a built-in debugging option, which outputs status updates for each container to the console whenever a change occurs. In this guide, we’ll explore:

  • Using the debug option: How to enable detailed logging for container statuses.
  • Interpreting Status Messages: Understanding the format of status updates in the console.

This feature is especially useful when troubleshooting dependencies and monitoring the initialization sequence of containers.

Enabling Debugging with debug: true

The compose.up function accepts an optional second argument, a configuration object, which can include debug. When debug: true is set, compose.up will output each container’s status as it changes. Here’s how to enable debugging:

import { createContainer, compose } from '@grlt-hub/app-compose';
const start: () => { api: {} };
const containerA = createContainer({ id: 'a', start });
const containerB = createContainer({ id: 'b', start, enable: () => false });
const containerC = createContainer({ id: 'c', start });
await compose.up([containerA, containerB, containerC], { debug: true });

With debug: true, the console will display status messages each time a container’s status changes.

Example Output

Here’s an example of what you might see in the console when debugging is enabled:

Terminal window
[2024-01-01T00:00:00.000Z] app-compose:
{
"a": "done",
"b": "off",
"c": "done"
}

In this example:

  • Each line displays a timestamp, followed by the statuses of each container.
  • The statuses show which containers are done, off, or in another state at any given time.

Benefits of Debugging

The debug option helps you:

  • Identify Initialization Order: Understand the sequence in which containers complete.
  • Monitor Dependencies: Ensure that containers with dependencies wait for the correct statuses before initializing.
  • Diagnose Issues: Quickly spot any containers stuck in unexpected statuses, such as off or fail.

Summary

In this guide, we explored how to use the debug option in compose.up to monitor container statuses in real time:

  • Enabling Debugging: Setting { debug: true } in the compose.up configuration outputs status updates to the console whenever a container’s status changes.
  • Interpreting Status Messages: The console log provides a timestamped snapshot of each container’s current status, helping to track progress and identify issues.

Using the debug option offers valuable insights into the initialization process, allowing you to verify dependency order, monitor container progress, and troubleshoot unexpected statuses with ease.