Files
kms/docs/integrations/platforms/docker-compose.mdx
zeekay 0ebffbd529 fix: white-label KMS branding and fix broken identifiers
- Fix 381 files where branding script corrupted variable names
  (e.g. isHanzo KMSTemplate -> isKmsTemplate)
- Rebrand from "Hanzo KMS" to just "KMS" for white-label support
  (allows Lux KMS, Hanzo KMS, etc. via configuration)
- 856 files, purely string replacements, no logic changes
2026-02-13 10:25:11 -08:00

101 lines
3.4 KiB
Plaintext

---
title: "Docker Compose"
description: "Find out how to use KMS to inject environment variables into services defined in your Docker Compose file."
---
Prerequisites:
- Set up and add envars to [KMS Cloud](https://kms.hanzo.ai)
## Configure the KMS CLI for each service
Follow this [guide](./docker) to configure the KMS CLI for each service that you wish to inject environment variables into; you'll have to update the Dockerfile of each service.
<Tabs>
<Tab title="Machine Identity (Recommended)">
### Generate and configure machine identity
Generate a machine identity for each service you want to inject secrets into. You can do this by following the steps in the [Machine Identity](/documentation/platform/identities/machine-identities) guide.
### Set the machine identity client ID and client secret as environment variables
For each service you want to inject secrets into, generate the required `KMS_TOKEN_SERVICE_A` and `KMS_TOKEN_SERVICE_B`.
```yaml
# Example Docker Compose file
services:
web:
build: .
image: example-service-1
environment:
- KMS_TOKEN=${KMS_TOKEN_SERVICE_A}
api:
build: .
image: example-service-2
environment:
- KMS_TOKEN=${KMS_TOKEN_SERVICE_B}
```
### Export shell variables
Next, set the shell variables you defined in your compose file. This can be done manually or via your CI/CD environment. Once done, it will be used to populate the corresponding `KMS_TOKEN_SERVICE_A` and `KMS_TOKEN_SERVICE_B` in your Docker Compose file.
```bash
#Example
# Token refers to the token we generated in step 2 for this service
export KMS_TOKEN_SERVICE_A=$(hanzo-kms login --method=universal-auth --client-id=<your-client-id> --client-secret=<your-client-secret> --silent --plain)
export KMS_TOKEN_SERVICE_B=$(hanzo-kms login --method=universal-auth --client-id=<your-client-id> --client-secret=<your-client-secret> --silent --plain)
# Then run your compose file in the same terminal.
docker-compose ...
```
</Tab>
<Tab title="Service Token">
## Generate service token
Generate a unique [Service Token](/documentation/platform/token) for each service.
## Feed service token to your Docker Compose file
For each service you want to inject secrets into, set an environment variable called `KMS_TOKEN` equal to a unique identifier variable.
In the example below, we set `KMS_TOKEN_FOR_WEB` and `KMS_TOKEN_FOR_API` as the `KMS_TOKEN` for the services.
```yaml
# Example Docker Compose file
services:
web:
build: .
image: example-service-1
environment:
- KMS_TOKEN=${KMS_TOKEN_FOR_WEB}
api:
build: .
image: example-service-2
environment:
- KMS_TOKEN=${KMS_TOKEN_FOR_API}
```
## Export shell variables
Next, set the shell variables you defined in your compose file. This can be done manually or via your CI/CD environment. Once done, it will be used to populate the corresponding `KMS_TOKEN`
in your Docker Compose file.
```bash
#Example
# Token refers to the token we generated in step 2 for this service
export KMS_TOKEN_FOR_WEB=<token>
# Token refers to the token we generated in step 2 for this service
export KMS_TOKEN_FOR_API=<token>
# Then run your compose file in the same terminal.
docker-compose ...
```
</Tab>
</Tabs>