Secrets in Docker Compose are used to securely store sensitive information such as passwords, API keys, and certificates. They allow you to keep this information out of your Compose files and separate from your code, improving the security and maintainability of your applications.
There are two ways to use secrets in Docker Compose:
- External secrets: These are secrets that are managed by an external secret management system, such as HashiCorp Vault or Azure Active Directory. To use external secrets in Docker Compose, you can reference them in your Compose file using the
secrets
key. For example:
version: '3.7'
services:
app:
image: my-app
secrets:
- my-secret
secrets:
my-secret:
external: true
In this example, the app
service uses the my-secret
secret, which is managed by an external secret management system.
- Inline secrets: These are secrets that are defined directly in your Compose file. To define inline secrets, you can use the
secret
key and specify the secret data as a string or as a reference to a file. For example:
version: '3.7'
services:
app:
image: my-app
secrets:
- my-secret
secrets:
my-secret:
file: ./my-secret.txt
In this example, the app
service uses the my-secret
secret, which is defined inline in the Compose file as a reference to the my-secret.txt
file.
For more information on using secrets in Docker Compose, you can refer to the official Docker Compose documentation.
Sources:
- Docker Compose: https://docs.docker.com/compose/compose-file/
- Docker Compose secrets: https://docs.docker.com/engine/swarm/secrets/
- HashiCorp Vault: https://developer.hashicorp.com/vault/docs/secrets
- Azure Active Directory OIDC SSO Configuration: https://developer.hashicorp.com/hcp/docs/hcp/admin/iam/sso/sso-aad-oidc
- Bitnami Helm charts: https://docs.bitnami.com/kubernetes/infrastructure/grafana-operator/get-started/compare-solutions
- Kuma configuration reference: https://kuma.io/docs/2.4.x/reference/kuma-cp
- Vault secrets engines: https://developer.hashicorp.com/vault/tutorials/getting-started/getting-started-secrets-engines
- Docker Compose build: https://docs.docker.com/compose/compose-file/build/
- Manage sensitive data with Docker secrets: https://docs.docker.com/engine/swarm/secrets/
- Static secrets: Key/value secrets engine: https://developer.hashicorp.com/vault/tutorials/secrets-management/static-secrets
- Versioned Key/value secrets engine: https://developer.hashicorp.com/vault/tutorials/secrets-management/versioned-kv
- Sealed Secrets: https://github.com/bitnami-labs/sealed-secrets