Skip to content

Commit f0dce1b

Browse files
aevesdockerndeloof
authored andcommitted
sdk docs: patch
Signed-off-by: aevesdocker <[email protected]>
1 parent 6e55832 commit f0dce1b

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

docs/sdk.md

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
# Using docker/compose SDK
1+
# Using the `docker/compose` SDK
22

33
The `docker/compose` package can be used as a Go library by third-party applications to programmatically manage
4-
containerized applications defined in Compose files. This SDK provides a comprehensive API that enables developers to
5-
integrate Compose functionality directly into their applications, allowing them to load, validate, and manage
6-
multi-container environments without relying on the Compose CLI. Whether you need to orchestrate containers as part of
4+
containerized applications defined in Compose files. This SDK provides a comprehensive API that lets you
5+
integrate Compose functionality directly into your applications, allowing you to load, validate, and manage
6+
multi-container environments without relying on the Compose CLI.
7+
8+
Whether you need to orchestrate containers as part of
79
a deployment pipeline, build custom management tools, or embed container orchestration into your application, the
810
Compose SDK offers the same powerful capabilities that drive the Docker Compose command-line tool.
911

10-
## Setup the SDK
12+
## Set up the SDK
1113

1214
To get started, create an SDK instance using the `NewComposeService()` function, which initializes a service with the
1315
necessary configuration to interact with the Docker daemon and manage Compose projects. This service instance provides
1416
methods for all core Compose operations including creating, starting, stopping, and removing containers, as well as
1517
loading and validating Compose files. The service handles the underlying Docker API interactions and resource
1618
management, allowing you to focus on your application logic.
1719

18-
## Example Usage
20+
## Example usage
1921

2022
Here's a basic example demonstrating how to load a Compose project and start the services:
2123

@@ -72,14 +74,14 @@ func main() {
7274
}
7375
```
7476

75-
This example demonstrates the core workflow: creating a service instance, loading a project from a Compose file, and
77+
This example demonstrates the core workflow - creating a service instance, loading a project from a Compose file, and
7678
starting the services. The SDK provides many additional operations for managing the lifecycle of your containerized
7779
application.
7880

7981
## Customizing the SDK
8082

8183
The `NewComposeService()` function accepts optional `compose.Option` parameters to customize the SDK behavior. These
82-
options allow you to configure I/O streams, concurrency limits, dry-run mode, and other advanced features:
84+
options allow you to configure I/O streams, concurrency limits, dry-run mode, and other advanced features.
8385

8486
```go
8587
// Create a custom output buffer to capture logs
@@ -94,63 +96,62 @@ options allow you to configure I/O streams, concurrency limits, dry-run mode, an
9496
)
9597
```
9698

97-
### Available Options
99+
### Available options
98100

99-
- **`WithOutputStream(io.Writer)`** - Redirect standard output to a custom writer
100-
- **`WithErrorStream(io.Writer)`** - Redirect error output to a custom writer
101-
- **`WithInputStream(io.Reader)`** - Provide a custom input stream for interactive prompts
102-
- **`WithStreams(out, err, in)`** - Set all I/O streams at once
103-
- **`WithMaxConcurrency(int)`** - Limit the number of concurrent operations against the Docker API
104-
- **`WithPrompt(Prompt)`** - Customize user confirmation behavior (use `AlwaysOkPrompt()` for non-interactive mode)
105-
- **`WithDryRun`** - Run operations in dry-run mode without actually applying changes
106-
- **`WithContextInfo(api.ContextInfo)`** - Set custom Docker context information
107-
- **`WithProxyConfig(map[string]string)`** - Configure HTTP proxy settings for builds
108-
- **`WithEventProcessor(progress.EventProcessor)`** - Receive progress events and operation notifications
101+
- `WithOutputStream(io.Writer)` - Redirect standard output to a custom writer
102+
- `WithErrorStream(io.Writer)` - Redirect error output to a custom writer
103+
- `WithInputStream(io.Reader)` - Provide a custom input stream for interactive prompts
104+
- `WithStreams(out, err, in)` - Set all I/O streams at once
105+
- `WithMaxConcurrency(int)` - Limit the number of concurrent operations against the Docker API
106+
- `WithPrompt(Prompt)` - Customize user confirmation behavior (use `AlwaysOkPrompt()` for non-interactive mode)
107+
- `WithDryRun` - Run operations in dry-run mode without actually applying changes
108+
- `WithContextInfo(api.ContextInfo)` - Set custom Docker context information
109+
- `WithProxyConfig(map[string]string)` - Configure HTTP proxy settings for builds
110+
- `WithEventProcessor(progress.EventProcessor)` - Receive progress events and operation notifications
109111

110112
These options provide fine-grained control over the SDK's behavior, making it suitable for various integration
111113
scenarios including CLI tools, web services, automation scripts, and testing environments.
112114

113-
## Tracking Operations with EventProcessor
115+
## Tracking operations with `EventProcessor`
114116

115117
The `EventProcessor` interface allows you to monitor Compose operations in real-time by receiving events about changes
116118
applied to Docker resources such as images, containers, volumes, and networks. This is particularly useful for building
117119
user interfaces, logging systems, or monitoring tools that need to track the progress of Compose operations.
118120

119-
### Understanding EventProcessor
121+
### Understanding `EventProcessor`
120122

121-
A Compose operation (like `Up`, `Down`, `Build`, etc.) performs a series of changes to Docker resources. The
123+
A Compose operation, such as `up`, `down`, `build`, performs a series of changes to Docker resources. The
122124
`EventProcessor` receives notifications about these changes through three key methods:
123125

124-
- **`Start(ctx, operation)`** - Called when a Compose operation begins (e.g., "up")
125-
- **`On(events...)`** - Called with progress events for individual resource changes (e.g., container starting, image
126-
being pulled)
127-
- **`Done(operation, success)`** - Called when the operation completes, indicating success or failure
126+
- `Start(ctx, operation)` - Called when a Compose operation begins, for example `up`
127+
- `On(events...)` - Called with progress events for individual resource changes, for example, container starting, image
128+
being pulled
129+
- `Done(operation, success)` - Called when the operation completes, indicating success or failure
128130

129131
Each event contains information about the resource being modified, its current status, and progress indicators when
130132
applicable (such as download progress for image pulls).
131133

132-
### Event Status Types
134+
### Event status types
133135

134136
Events report resource changes with the following status types:
135137

136-
- **Working** - Operation is in progress (e.g., creating, starting, pulling)
137-
- **Done** - Operation completed successfully
138-
- **Warning** - Operation completed with warnings
139-
- **Error** - Operation failed
138+
- Working - Operation is in progress, for example, creating, starting, pulling
139+
- Done - Operation completed successfully
140+
- Warning - Operation completed with warnings
141+
- Error - Operation failed
140142

141143
Common status text values include: `Creating`, `Created`, `Starting`, `Started`, `Running`, `Stopping`, `Stopped`,
142144
`Removing`, `Removed`, `Building`, `Built`, `Pulling`, `Pulled`, and more.
143145

144-
### Built-in EventProcessor Implementations
146+
### Built-in `EventProcessor` implementations
145147

146148
The SDK provides three ready-to-use `EventProcessor` implementations:
147149

148-
- **`progress.NewTTYWriter(io.Writer)`** - Renders an interactive terminal UI with progress bars and task lists
150+
- `progress.NewTTYWriter(io.Writer)` - Renders an interactive terminal UI with progress bars and task lists
149151
(similar to the Docker Compose CLI output)
150-
- **`progress.NewPlainWriter(io.Writer)`** - Outputs simple text-based progress messages suitable for non-interactive
152+
- `progress.NewPlainWriter(io.Writer)` - Outputs simple text-based progress messages suitable for non-interactive
151153
environments or log files
152-
- **`progress.NewJSONWriter()`** - Render events as JSON objects
153-
- **`progress.NewQuietWriter()`** - (default) Silently processes events without producing any output
154-
155-
Using `EventProcessor`, a custom UI can be plugged into docker/compose
154+
- `progress.NewJSONWriter()` - Render events as JSON objects
155+
- `progress.NewQuietWriter()` - (Default) Silently processes events without producing any output
156156

157+
Using `EventProcessor`, a custom UI can be plugged into `docker/compose`.

0 commit comments

Comments
 (0)