Configs top-level element


目录

{{% include "compose/configs.md" %}}

Services can only access configs when explicitly granted by a configs attribute within the services top-level element.

By default, the config:

The top-level configs declaration defines or references configuration data that is granted to services in your Compose application. The source of the config is either file, environment, content, or external.

Example 1

<project_name>_http_config is created when the application is deployed, by registering the content of the httpd.conf as the configuration data.

configs:
  http_config:
    file: ./httpd.conf

Alternatively, http_config can be declared as external. Compose looks up http_config to expose the configuration data to relevant services.

configs:
  http_config:
    external: true

Example 2

External configs lookup can also use a distinct key by specifying a name.

The following example modifies the previous one to look up a config using the parameter HTTP_CONFIG_KEY. The actual lookup key is set at deployment time by the interpolation of variables, but exposed to containers as hard-coded ID http_config.

configs:
  http_config:
    external: true
    name: "${HTTP_CONFIG_KEY}"

Example 3

<project_name>_app_config is created when the application is deployed, by registering the inlined content as the configuration data. This means Compose infers variables when creating the config, which allows you to adjust content according to service configuration:

configs:
  app_config:
    content: |
      debug=${DEBUG}
      spring.application.admin.enabled=${DEBUG}
      spring.application.name=${COMPOSE_PROJECT_NAME}

Example 4

<project_name>_simple_config is created when the application is deployed, using the value of an environment variable as the configuration data. This is useful for simple configuration values that don’t require interpolation:

configs:
  simple_config:
    environment: "SIMPLE_CONFIG_VALUE"

If external is set to true, all other attributes apart from name are irrelevant. If Compose detects any other attribute, it rejects the Compose file as invalid.


版本号 #2
由 壳壳虫 创建于 2026-10-31 19:42:43 UTC
由 壳壳虫 更新于 2026-10-31 19:42:44 UTC