# Set an empty environment variable in using rancher-compose

**URL:** <https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903>\
**Category:** Rancher 1.x\
**Created:** [September 6, 2016, 12:52pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903 "2016-09-06T12:52:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 6, 2016, 12:52pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/1 "2016-09-06T12:52:40Z")

</div>

How does one set an empty environment variable in using `rancher-compose`?

I’ve tried:

- `docker-compose.yml`

```auto
environment:
    EMPTY1:
    EMPTY2: ""
    EMPTY3: ''
    EMPTY4: null
    EMPTY5: ~

```

But it doesn’t create empty variables.

It’s possible to do so via UI. Empty variables are visible in API and container:

```json
"launchConfig": {
  "environment": {
    "EMPTY1": '',
    "EMPTY2": '',
    "EMPTY3": '',
    "EMPTY4": '',
    "EMPTY5": '',
  }

```

`env` command output from container:

```bash
/ # env
HOSTNAME=ba962f043e17
SHLVL=2
HOME=/root
TERM=xterm-256color
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
EMPTY1=
EMPTY2=
EMPTY3=
EMPTY4=
EMPTY5=

```

Details:

- Rancher: **v1.1.1**
- Cattle: **v0.165.7**
- User Interface: **v1.1.12**
- Rancher Compose: **v0.8.6**

* * *

P.S. I’m asking this question here, since [my comment on the related GitHub issue](https://github.com/rancher/rancher/issues/4990#issuecomment-243162987) haven’t attracted anyone’s attention.

---

<div class="post-metadata">

**Author:** ![sjiveson](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sjiveson/32/966_2.png) [@sjiveson](https://forums.suse.com/u/sjiveson)\
**Post date:** [September 8, 2016, 10:51am UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/2 "2016-09-08T10:51:57Z")

</div>

You’re syntax and spacing seem wrong. From here: [https://docs.docker.com/compose/compose-file/#/environment](https://docs.docker.com/compose/compose-file/#/environment).

```
environment:
  RACK_ENV: development
  SHOW: 'true'
  SESSION_SECRET:

environment:
  - RACK_ENV=development
  - SHOW=true
  - SESSION_SECRET
```

---

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 8, 2016, 11:37am UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/3 "2016-09-08T11:37:41Z")

</div>

Well, I’m using an array notation and it works fine for other environment variables. It’s empty ones that I’m struggling with.

I’ve tried to use a dictionary, but it’s just assigns values literally:

- `docker-compose.yml`

```auto
  environment:
    - EMPTY1
    - EMPTY2=""
    - EMPTY3=''
    - EMPTY4=null
    - EMPTY5=~

```

`env` command output from container:

```bash
/ # env
HOSTNAME=18a158c41d55
SHLVL=2
HOME=/root
TERM=xterm-256color
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
EMPTY2=""
EMPTY3=''
PWD=/
EMPTY4=null
EMPTY5=~

```

---

<div class="post-metadata">

**Author:** ![sjiveson](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sjiveson/32/966_2.png) [@sjiveson](https://forums.suse.com/u/sjiveson)\
**Post date:** [September 8, 2016, 12:01pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/4 "2016-09-08T12:01:08Z")

</div>

It doesn’t look like you’ve tried this:

```
- EMPTY1=
```

---

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 8, 2016, 12:09pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/5 "2016-09-08T12:09:14Z")

</div>

> [@sjiveson](#):
>
> It doesn’t look like you’ve tried this:
> 
> - EMPTY1=

Yep, missed that. I’ve tried it now and it doesn’t work (and it shouldn’t according to docs). It will create env. variable only if it exists on a machine running `rancher-compose`.

---

<div class="post-metadata">

**Author:** ![sjiveson](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sjiveson/32/966_2.png) [@sjiveson](https://forums.suse.com/u/sjiveson)\
**Post date:** [September 8, 2016, 1:33pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/6 "2016-09-08T13:33:29Z")

</div>

OK, fair enough, that’s me out of ideas.

Why do you need an empty variable anyway?

---

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 8, 2016, 3:30pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/7 "2016-09-08T15:30:36Z")

</div>

I’m using [richarvey/nginx-php-fpm/](https://hub.docker.com/r/richarvey/nginx-php-fpm) container with custom startup script that does templating via `sed`. It pulls templates from env. variables and if they don’t exist, templates are not replaced.

Example:

- `docker-compose.yml`

```auto
environment:
  CI_PROTO: http
  CI_DN: www.example.com
  CI_BASE: /app

```

- `config.php` in container

```php
define('ASSETS_URL', '$$_CI_PROTO_$$://$$_CI_DN_$$/$$_CI_BASE_$$');

```

So if I’d like to put my app in the root directory, putting an empty `CI_BASE` env. variable would be the easiest way. But since I can’t, I get this:

```php
define('ASSETS_URL', 'http://www.example.com/$$_CI_BASE_$$');

```

Sure, this can be fixed easily one way or another (which I’ve already done), but I’d like to know if there is more straightforward way.

---

<div class="post-metadata">

**Author:** ![sjiveson](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sjiveson/32/966_2.png) [@sjiveson](https://forums.suse.com/u/sjiveson)\
**Post date:** [September 8, 2016, 3:46pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/8 "2016-09-08T15:46:44Z")

</div>

I see, thanks for providing the info, always useful to see what people are doing.

I mostly use Confd and that (or rather Go text templating that it uses) has an if operator where a value won’t be populated if the environment variable doesn’t exist. I’m not suggesting your switch to it, but perhaps it might inform a future choice.

Cheers

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [September 8, 2016, 9:47pm UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/9 "2016-09-08T21:47:05Z")

</div>

@beatcracker This doesn’t work with rancher-compose now. Can you file an issue in Github?

---

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 9, 2016, 9:56am UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/10 "2016-09-09T09:56:58Z")

</div>

Thanks for the tip! ConfD is definitely looks promising.

---

<div class="post-metadata">

**Author:** ![beatcracker](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/beatcracker/32/1482_2.png) [@beatcracker](https://forums.suse.com/u/beatcracker)\
**Post date:** [September 9, 2016, 10:41am UTC](https://forums.suse.com/t/set-an-empty-environment-variable-in-using-rancher-compose/3903/11 "2016-09-09T10:41:45Z")

</div>

Sure, thanks for reply!

[https://github.com/rancher/rancher/issues/5935](https://github.com/rancher/rancher/issues/5935)
