# Filebeat can not get enviroment variable in docker

**URL:** <https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [April 22, 2019, 9:23am UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829 "2019-04-22T09:23:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ducminhle](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@ducminhle](https://discuss.elastic.co/u/ducminhle)\
**Post date:** [April 22, 2019, 9:23am UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/1 "2019-04-22T09:23:20Z")

</div>

Hi All,

Here is my config in filebeat.yml:

**fields:**  
**env: '${SPRING\_PROFILES\_ACTIVE}'**

* * *

Result in the container is:  
root@07acb280f9e5:/# echo ${SPRING\_PROFILES\_ACTIVE}  
perf15

* * *

But I got issue went container start filebeat (version 5.1.1):  
Exiting: error unpacking config data: missing field accessing 'fields.env' (source:'/etc/filebeat/filebeat.yml')

* * *

I have seen a topic: [Cannot use env variables in filebeat!](https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270) but in my container cannot use the command: systemctl import-environment:  
root@07acb280f9e5:/# systemctl import-environment  
bash: systemctl: command not found

* * *

Do you have another idea to solve this problem?

Thank you.

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [April 23, 2019, 9:22pm UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/2 "2019-04-23T21:22:21Z")

</div>

Have you build a customer container?

How do you start filebeat from within the container?

---

<div class="post-metadata">

**Author:** ![ducminhle](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@ducminhle](https://discuss.elastic.co/u/ducminhle)\
**Post date:** [April 24, 2019, 2:45am UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/3 "2019-04-24T02:45:47Z")

</div>

Yes, it's a customer container.

I have a file startup.sh it run when start container, in this file it have a command:

* * *

FROM debian:stretch  
....  
....  
....

# Start filebeat  
/etc/init.d/filebeat start

* * *

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [April 24, 2019, 12:29pm UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/4 "2019-04-24T12:29:24Z")

</div>

Which init script are you using? Init scripts normally start processes in the background and return. In this case the container will shutdown right after startup, cause the script didn't block.

Have you had a look at the official docker containers? [https://github.com/elastic/beats-docker](https://github.com/elastic/beats-docker)

---

<div class="post-metadata">

**Author:** ![ducminhle](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@ducminhle](https://discuss.elastic.co/u/ducminhle)\
**Post date:** [April 24, 2019, 6:09pm UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/5 "2019-04-24T18:09:26Z")

</div>

Init script has been created default after command install filebeat 5.5.1 (dpkg -i filebeat-5.5.1-amd64.deb - downloaded from [https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.5.1-amd64.deb](https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.5.1-amd64.deb)) in Docker file. This way can not work on Docker container?

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [April 25, 2019, 10:32am UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/6 "2019-04-25T10:32:35Z")

</div>

No, init scripts are in general not supposed to be used directly from within docker containers. This is true for any init script, not just Beats.  
Users wanting to run multiple services in one container often use [runit](http://smarden.org/runit/). But this is not required just for running a container. Tools/services often have custom scripts as entry-points. See official docker containers.

Why do you build your own container instead of building on or reusing the existing containers?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 23, 2019, 10:32am UTC](https://discuss.elastic.co/t/filebeat-can-not-get-enviroment-variable-in-docker/177829/7 "2019-05-23T10:32:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
