# Setting "Service Variables" with docker-compose

**URL:** <https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101>\
**Category:** Project help\
**Created:** [March 28, 2021, 4:53pm UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101 "2021-03-28T16:53:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caspar](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/caspar/32/1328_2.png) [@Caspar](https://forums.balena.io/u/Caspar)\
**Post date:** [March 28, 2021, 4:53pm UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101/1 "2021-03-28T16:53:59Z")

</div>

Hello,

i am changing the basicstation project (lorawan / ttn gateway) from single docker to docker-compose atm and i run into the problem to set service variables for the different containers automaticly. In the original project inside the balena.yml the variables are set this way:

> data:  
> applicationEnvironmentVariables:  
> - GW\_GPS: false  
> - GW\_RESET\_PIN: 11  
> - GW\_RESET\_GPIO: 17  
> - MODEL: SX1301  
> - TTN\_STACK\_VERSION: 2  
> - TTN\_REGION: eu  
> - GW\_ID: 0  
> - GW\_KEY: 0  
> - TC\_KEY: 0

now it moved everything in a sub folder and created a docker-compose.yml and i would love to created service variables (those above for a container named “gateway”) and not environment variables like in the example above. Is there a way to achieve this? Or does the user have to create the service variables “by hand”?

thank you very much!

Cheers Caspar

---

<div class="post-metadata">

**Author:** ![chrisys](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrisys/32/1731_2.png) [@chrisys](https://forums.balena.io/u/chrisys)\
**Post date:** [March 29, 2021, 11:49am UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101/4 "2021-03-29T11:49:25Z")

</div>

Hey @Caspar!

This is a great question, but no straightforward answer as such so forgive me for the long reply! The `balena.yml` file applies to a single or multicontainer application as a whole and is used whenever the ‘Deploy with balena’ button is clicked to set up the environment variables automatically. At the moment, there’s no way to specify within the `balena.yml` file what service a variable belongs to in order to specify service variables and so they are all added at the application level. This is something we would want to enable in the future for sure, but ultimately you’re right in that today we don’t have a way to add these automatically in the same way as the application environment variables. I’ll log this internally to make sure we’re recording your need for the feature. 🙂

The application level variables from the `balena.yml` as you have it above will still apply to the new `gateway` container you’ve created in the multicontainer application, but they’ll also apply to all of the other containers as well. This shouldn’t be a problem unless you need to set one of these variables to different values on a per-container basis.

There are options to create the [service variables programmatically via the API](https://www.balena.io/docs/reference/api/resources/service_environment_variable/) and I appreciate this may not be of use in the scenario you describe, but I’m linking here for completeness anyway.

I hope this helps but if not let us know, maybe in a bit more detail and we’ll see if we can come up with any other methods to help achieve the same result.

---

<div class="post-metadata">

**Author:** ![rapha](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/rapha/32/1239_2.png) [@rapha](https://forums.balena.io/u/rapha)\
**Post date:** [August 22, 2023, 3:26pm UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101/6 "2023-08-22T15:26:48Z")

</div>

Is there a way to set these variables and push them using `balena deploy` ? Or do we have to go through the API?

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [August 23, 2023, 11:30am UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101/7 "2023-08-23T11:30:23Z")

</div>

Hello @rapha what would you like to achieve on this? updating the variables from your fleet? did you try balenaCloud?

Let us know more details of what would you like to do.

Thanks

---

<div class="post-metadata">

**Author:** ![rapha](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/rapha/32/1239_2.png) [@rapha](https://forums.balena.io/u/rapha)\
**Post date:** [October 18, 2023, 1:40pm UTC](https://forums.balena.io/t/setting-service-variables-with-docker-compose/279101/8 "2023-10-18T13:40:05Z")

</div>

@mpous this is not relevant for us any more. We used to have air-gapped devices that don’t connect to the fleet at first deployment. So we wanted a way to set up services with envs without having to have contact to the balena cloud.
