Telegraf in a docker container with custom plugins - flag not defined error

I wish to use telegraf with some custom plugins in a docker container (as [[“input.exec”]]). To do so I am using this flag: –config-directory, which works perfectly in the command line but I can’t make it work inside a docker.

My setup : Ubuntu 16.04, docker 17.03, docker-compose 1.13.0

Extract of my docker-compose file :

version: '3’
image: telegraf:1.3.2
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- ./telegraf.d/:/etc/telegraf/telegraf.d/ # custom *.conf
- ./plugins/:/etc/telegraf/plugins/ # custom plugins
- “–config-directory /etc/telegraf/telegraf.d”

Running with:

docker-compose up


telegraf_1 | flag provided but not defined: -config-directory /etc/telegraf/telegraf.d

What am I doing wrong ?

Do I need to build my custom telegraf container ?

I tried that too, with FROM: telegraf:1.3.2 and COPY for the config files and plugins, and CMD=["-config-directory /etc/telegraf/telegraf.d/]), but not a complete build (with FROM:alpine-linux for instance)

Everything works as expected on my machine

  • in ./plugins, I have the code for the plugins (eg: in python), which output metrics in json format
  • in ./telegraf.d, I put my conf file (eg: pythontimer.conf)

My command line is :

telegraf -config ./telegraf.conf --config-directory ./telegraf.d

One example of conf file is:

 command= "<fullpath>/plugins/"
 data_format = "json"
 name_suffix = "_custom"
 interval = "10s"

@Nilct From the error message it looks like you are missing a -. Have you tried execing into the container and running the command manually to ensure this is a docker issue?

Thanks for your answer.

I tried “–config” and “-config” and both work on the command line (not inside the container though). I ended up building a custom container (installing telegraf debian package) and a file with the flags.

I’m not a docker-compose expert, but it looks to me like it is passing -config-directory /etc/telegraf/telegraf.d as a single argument, when it should be two args: -config-directory and /etc/telegraf/telegraf.d. Try removing the quotes:

- --config-directory /etc/telegraf/telegraf.d

Both single and double dash should work for all the arguments, but I suggest using double dash as it should be more resilient in the case we move to a more advanced flag library sometime in the future.


Thanks! That was exactly my mistake!
I am rolling back to using the official telegraf container.