# Using extension fields in your Swarm YAML to emulate the compose env\_file feature

**URL:** <https://community.replicated.com/t/using-extension-fields-in-your-swarm-yaml-to-emulate-the-compose-env-file-feature/163>\
**Category:** Packaging an application\
**Created:** [June 6, 2018, 5:47pm UTC](https://community.replicated.com/t/using-extension-fields-in-your-swarm-yaml-to-emulate-the-compose-env-file-feature/163 "2018-06-06T17:47:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethanm](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/ethanm/32/11_2.png) [@ethanm](https://community.replicated.com/u/ethanm)\
**Post date:** [June 6, 2018, 5:47pm UTC](https://community.replicated.com/t/using-extension-fields-in-your-swarm-yaml-to-emulate-the-compose-env-file-feature/163/1 "2018-06-06T17:47:59Z")

</div>

Replicated does not currently support the Docker Compose feature [env\_file](https://docs.docker.com/compose/compose-file/#env_file) which makes it possible to extract your common environment variables and clean up your spec.

Docker added [extension fields](https://docs.docker.com/compose/compose-file/#extension-fields) as of Compose version 3.4. This makes it possible to re-use configuration fragments in your Compose YAML. We can make use of YAML [anchors and aliases](http://yaml.org/spec/1.2/spec.html#id2765878) to achieve something similar to the [env\_file](https://docs.docker.com/compose/compose-file/#env_file) feature.

```auto
---
# kind: scheduler-swarm

version: '3.4'

x-custom:
  shared_env: &shared_env
    RELEASE_CHANNEL: unstable
    VERSION: 2.21.0

services:
  replicated:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated
  replicated-ui:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated-ui
  replicated-operator:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated-operator

```

---

<div class="post-metadata">

**Author:** ![Bryan\_Tayler](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@Bryan\_Tayler](https://community.replicated.com/u/Bryan_Tayler)\
**Post date:** [August 9, 2018, 11:23am UTC](https://community.replicated.com/t/using-extension-fields-in-your-swarm-yaml-to-emulate-the-compose-env-file-feature/163/2 "2018-08-09T11:23:33Z")

</div>

thank you that was really helpfull.  
i have thoght one qusetion, can i reset the value in the extension fields  
ie:  
x-custom:  
shared\_env: &shared\_env  
DB\_DONE: 0  
services:  
postgis-db:  
environment:  
\<\<: \*shared\_env  
and in the build script after every thing is done  
DB\_DONE=1  
it worked just for the current conatiner

---

<div class="post-metadata">

**Author:** ![grant](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/grant/32/9_2.png) [@grant](https://community.replicated.com/u/grant)\
**Post date:** [March 22, 2022, 9:02pm UTC](https://community.replicated.com/t/using-extension-fields-in-your-swarm-yaml-to-emulate-the-compose-env-file-feature/163/3 "2022-03-22T21:02:12Z")

</div>

Unlisted on March 22, 2022, 9:02pm UTC


