Skip to content

Commit 681b018

Browse files
committed
add how-to page explaining usage of Compose provider services
Signed-off-by: Guillaume Lours <[email protected]>
1 parent ac01a44 commit 681b018

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Use provider services
3+
description: Learn how to use provider services in Docker Compose to integrate external capabilities into your applications
4+
keywords: compose, docker compose, provider, services, platform capabilities, integration, model runner, ai
5+
weight: 112
6+
params:
7+
sidebar:
8+
badge:
9+
color: green
10+
text: New
11+
---
12+
13+
{{< summary-bar feature_name="Compose provider services" >}}
14+
15+
Docker Compose supports provider services, which allow integration with services whose lifecycles are managed by third-party components rather than by Compose itself.
16+
This feature enables you to define and utilize platform-specific services without the need for manual setup or direct lifecycle management.
17+
18+
## Prerequisites
19+
20+
- Docker Compose v2.36 or later
21+
22+
## What are provider services?
23+
24+
Provider services are a special type of service in Compose that represents platform capabilities rather than containers.
25+
They allow you to declare dependencies on specific platform features that your application needs.
26+
27+
When you define a provider service in your Compose file, Compose works with the platform to provision and configure
28+
the requested capability, making it available to your application services.
29+
30+
## Using provider services
31+
32+
To use a provider service in your Compose file, you need to:
33+
34+
1. Define a service with the `provider` attribute
35+
2. Specify the `type` of provider you want to use
36+
3. Configure any provider-specific options
37+
4. Declare dependencies from your application services to the provider service
38+
39+
Here's a basic example:
40+
41+
```yaml
42+
services:
43+
database:
44+
provider:
45+
type: awesomecloud
46+
options:
47+
type: mysql
48+
foo: bar
49+
app:
50+
image: myapp
51+
depends_on:
52+
- database
53+
```
54+
55+
Notice the dedicated `provider` attribute in the `database` service.
56+
This attribute specifies that the service is a provider and lets you define options specific to that provider type.
57+
58+
The `depends_on` attribute in the `app` service specifies that it depends on the `database` service.
59+
This means that the `database` service will be started before the `app` service, allowing the provider information
60+
to be injected into the `app` service.
61+
62+
## How it works
63+
64+
During the `docker compose up` process, Compose identifies provider services and works with the platform to provision
65+
the requested capabilities. The platform then provides Compose with information about how to access the provisioned resource.
66+
67+
This information is passed to services that declare a dependency on the provider service, typically through environment
68+
variables. The naming convention for these variables is:
69+
70+
```env
71+
<<PROVIDER_SERVICE_NAME>>_<<VARIABLE_NAME>>
72+
```
73+
74+
For example, if your provider service is named `database`, your application service might receive environment variables like:
75+
76+
- `DATABASE_URL` with the URL to access the provisioned resource
77+
- `DATABASE_TOKEN` with an authentication token
78+
- Other provider-specific variables
79+
80+
Your application can then use these environment variables to interact with the provisioned resource.
81+
82+
## Provider types
83+
84+
The `type` field in a provider service references the name of either:
85+
86+
1. A Docker CLI plugin (e.g., `docker-model`)
87+
2. A binary available in the user's PATH
88+
89+
When Compose encounters a provider service, it looks for a plugin or binary with the specified name to handle the provisioning of the requested capability.
90+
91+
For example, if you specify `type: model`, Compose will look for a Docker CLI plugin named `docker-model` or a binary named `model` in the PATH.
92+
93+
```yaml
94+
services:
95+
ai-runner:
96+
provider:
97+
type: model # Looks for docker-model plugin or model binary
98+
options:
99+
model: ai/example-model
100+
```
101+
102+
The plugin or binary is responsible for:
103+
104+
1. Interpreting the options provided in the provider service
105+
2. Provisioning the requested capability
106+
3. Returning information about how to access the provisioned resource
107+
108+
This information is then passed to dependent services as environment variables.
109+
110+
## Benefits of using provider services
111+
112+
Using provider services in your Compose applications offers several benefits:
113+
114+
1. **Simplified configuration**: You don't need to manually configure and manage platform capabilities
115+
2. **Declarative approach**: You can declare all your application's dependencies in one place
116+
3. **Consistent workflow**: You use the same Compose commands to manage your entire application, including platform capabilities
117+
118+
## Creating your own provider
119+
120+
If you want to create your own provider to extend Compose with custom capabilities, you can implement a Compose plugin that registers provider types.
121+
122+
For detailed information on how to create and implement your own provider, refer to the [Compose Extensions documentation](https://github.com/docker/compose/blob/main/docs/extension.md).
123+
This guide explains the extension mechanism that allows you to add new provider types to Compose.
124+
125+
## Reference
126+
127+
- [Docker Model Runner documentation](/manuals/ai/model-runner.md)
128+
- [Compose Extensions documentation](https://github.com/docker/compose/blob/main/docs/extension.md)

data/summary.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Compose model runner:
109109
requires: Docker Compose [2.35.0](/manuals/compose/releases/release-notes.md#2300) and later, and Docker Desktop 4.41 and later
110110
Compose OCI artifact:
111111
requires: Docker Compose [2.34.0](/manuals/compose/releases/release-notes.md#2340) and later
112+
Compose provider services:
113+
requires: Docker Compose [2.36.0](/manuals/compose/releases/release-notes.md) and later
112114
Compose replace file:
113115
requires: Docker Compose [2.24.4](/manuals/compose/releases/release-notes.md#2244) and later
114116
Compose required:

0 commit comments

Comments
 (0)